So I tried to do a tool, well, I've done it hundred of times, not like this, last time was with a Friaza Tutorial on YouTube. What I want it to do is spawn a part, and shoot it to where ever my Torso is facing. I thought it was lookVector, but I tried it, and it failed
function ClickityClick() local Tool = script.Parent local Handle = Tool.Handle Backpack = Tool.Parent Char = Backpack.Parent Char:FindFirstChild(Char, "Torso") if(Torso ~= nil) then Handle.BrickColor = BrickColor.new("Really red") print("The Handle Color has changed into"..Handle.BrickColor) NP =Instance.new("Part") NP.Shape = "Ball" NP.BrickColor = BrickColor.new("Toothpaste") NP.CFrame = Torso.CFrame end end script.Parent.Activated:connect(ClickityClick)
:FindFirstChild
is a method (note the colon :
as opposed to dot .
).
The first parameter is just the name you're looking for.
In addition, when you look for something, you need to store it somewhere. You refer to Torso
but never defined what Torso
is.
To solve these problems, line 06 should be:
local Torso = Char:FindFirstChild("Torso")
I don't quite understand what you are requesting -- but this isn't a request site so here's an interpretation that should at least help you.
The direction the Torso is facing is its CFrame
's lookVector
. To throw something in that direction, we multiply that by the speed we want and set the object's velocity to that, e.g.,
NP.Velocity = 500 * Torso.CFrame.lookVector
Note that since NP
is positioned inside of Torso
(see line 16) this probably won't work too well. We should position it a little forward so that it doesn't hit the body.
NP.CFrame = Torso.CFrame + Torso.CFrame.lookVector * 2; -- Two studs in front of the Torso