generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Function help (Raycast)

Previous Thread :: Next Thread 
Sharpshooter26 is not online. Sharpshooter26
Joined: 26 May 2010
Total Posts: 5166
08 Sep 2012 09:37 PM
This isn't firing onclick
---------------------------------------------------------------------------------------
function Fire()

if script.Parent.Ammo.Value >= 1 then

local NewPart = Part:Clone() --creating a new part
local Ray = Ray.new(Tool.Handle.CFrame.p, (mouse.Hit.p-Tool.Handle.CFrame.p).unit*300) --creating the ray, (Ray.new(origin,direction) the .unit*300 is the distance
local Hit,Position = game.Workspace:FindPartOnRay(Ray,Character) --Getting information from the ray
local Distance = (Position - Tool.Handle.CFrame.p).magnitude --Getting distance from the Ray's postion and the tool
NewPart.Size = Vector3.new(0.2,0.2,Distance) --Setting up the part
NewPart.CFrame = CFrame.new(Position, Tool.Handle.CFrame.p) * CFrame.new(0,0,-Distance/2)
NewPart.Parent = Character
game.Debris:AddItem(NewPart,0.1) --Dont like spammed parts.
print("m")
script.Parent.Ammo.Value = script.Parent.Ammo.Value - 1

else Reload(Key)
end
end
-----------------------------------------------------------------------------------------

Mouse.Button1Down:connect(function()
Fire()
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
08 Sep 2012 09:37 PM
Thanks for the info!
Report Abuse
Sharpshooter26 is not online. Sharpshooter26
Joined: 26 May 2010
Total Posts: 5166
08 Sep 2012 09:38 PM
It's broken.....so uh

go ahead and take it
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
08 Sep 2012 09:39 PM
No thank you.
Report Abuse
Sharpshooter26 is not online. Sharpshooter26
Joined: 26 May 2010
Total Posts: 5166
08 Sep 2012 09:39 PM
Anyone have an idea why it isnt firing?
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
08 Sep 2012 09:42 PM
Are there any errors in the output?
Report Abuse
Sharpshooter26 is not online. Sharpshooter26
Joined: 26 May 2010
Total Posts: 5166
08 Sep 2012 09:42 PM
None, and the two otehr functions I have are working fine.

Also, all the variables used are defined.
Report Abuse
Sharpshooter26 is not online. Sharpshooter26
Joined: 26 May 2010
Total Posts: 5166
08 Sep 2012 09:44 PM
All these are defined in the beggining of the script:

local Character = game.Players.LocalPlayer.Character
local Tool = script.Parent
local Part = Instance.new("Part")
Part.Transparency = .5
Part.BrickColor = BrickColor.new("Lime green")
Part.Anchored = true
Part.CanCollide = false
Part.FormFactor = "Custom"
Report Abuse
Sharpshooter26 is not online. Sharpshooter26
Joined: 26 May 2010
Total Posts: 5166
08 Sep 2012 09:49 PM
Anyone know?
Report Abuse
Sharpshooter26 is not online. Sharpshooter26
Joined: 26 May 2010
Total Posts: 5166
08 Sep 2012 09:54 PM
D:
Report Abuse
Sharpshooter26 is not online. Sharpshooter26
Joined: 26 May 2010
Total Posts: 5166
08 Sep 2012 10:32 PM
Help....?
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
08 Sep 2012 10:37 PM
change it to Fire(mouse)
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
08 Sep 2012 10:40 PM
MouseButton1Click:connect


?
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
08 Sep 2012 10:56 PM
Or Maybe even ClickDetector.MouseClick:connect if it's a click detector
Report Abuse
PoopsAndPeepees is not online. PoopsAndPeepees
Joined: 05 Sep 2012
Total Posts: 55
08 Sep 2012 10:57 PM
Did you add a parent to the Part?

All I see is local Part = Instance.new("Part")

Try

local Part = Instance.new("Part", Workspace)
Report Abuse
Sharpshooter26 is not online. Sharpshooter26
Joined: 26 May 2010
Total Posts: 5166
09 Sep 2012 08:24 AM
@Poops

The raycast script works fine.


It just isnt firing

I tried switching all Mouses to mouse still isnt working

09:22:47 - Players.Player262.Backpack.TurretTool.RayCaster:47: attempt to index local 'mouse' (a nil value)
09:22:47 - Script "Players.Player262.Backpack.TurretTool.RayCaster", Line 47 - global Fire
09:22:47 - Script "Players.Player262.Backpack.TurretTool.RayCaster", Line 71
09:22:47 - stack end
09:22:47 - Disconnected event because of exception
Report Abuse
8SunTzu8 is not online. 8SunTzu8
Joined: 30 Sep 2011
Total Posts: 8199
09 Sep 2012 08:31 AM
This seemed like an obvious error.

You need to connect a function for when you equip the tool, then define mouse.

function Load(cheeselover)
mouse = cheeselover
end

script.Parent.Equipped:connect(Load) --Not sure about the event's name.

You need to make sure that mouse exists, I don't really know a more simple way to do this, but the above function usually works well for me.

Let us know if it works out.

"If you want to become a Developer or Innovator for CSA, contact me."
Report Abuse
coltman188888 is not online. coltman188888
Joined: 09 May 2009
Total Posts: 9330
09 Sep 2012 09:47 AM
Obvious error. Look at the bottom, you forgot a ).
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image