I keep getting an error on the following code that says Torso is a nil value, which does not make sense to me. This is part of a time bomb weapon. When the bomb hits a player, I want it to float in front of them for a few second to build suspense before exploding. It sticks to the player's torso as intended, so my idea was that if the torso's CFrame was changed (the player moves) then the bomb would change to always be in front of the torso. Maybe there is an easier way to do this without running a "Changed" function over and over again, but I'm out of ideas. Let me know if you want to see the entire code.
local function OnTouched(otherPart)
if otherPart.Parent:findFirstChild("Humanoid") then
if Rocket and otherPart then
Torso = otherPart.Parent:findFirstChild("Torso")
dir = Torso.CFrame.lookVector
pos = Torso.Position + (dir*3)
Touched = true
end
end
end
Torso.Changed:connect(function()
game.Workspace.Baseplate:Destroy()
if Touched == true then
Rocket.CFrame = CFrame.new(pos, pos + dir)
end
end)
Rocket.Touched:connect(OnTouched)

10 comments
Why are you using findFirstChild
Probably because what you're detecting is R15. R15 doesn't use Torso.
Zenith_Lord - Thank you! I didn't realize that so I will look into it and try it with an R6 player.
change
findFirstChildtoFindFirstChildandconnecttoConnect. The former versions of both are deprecated.Also I just realized that Torso.Changed is a typo. I meant to say Torso.CFrame.Changed.
No, that would error. ^
I've fixed these things and it still says Torso is nil, which I know isn't true because if I add Torso:Destroy() then it destroys. I think Torso.CFrame.Changed is the problem so I'm going to find another method to do this. Thank you for telling me about the deprecated things, I've used the wrong one several times in other code.
I know this is probably bad but I use humanoid.Changed to check for character movement.
I think there is a better way to detect player movement. humanoid.Running.
Thank you to everyone who commented on this question, I found a tutorial on making a floating object on the Roblox wiki that I had not seen before. After reading that, I found that welds work way easier and I was making a simple task too complicated. I didn't realize welds could do that but it is working great so I'm just gonna stick with it. BodyPosition would also have a similar effect.