Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

"Change" function with Torso CFrame coming up nil?

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

0

Why are you using findFirstChild

0

Probably because what you're detecting is R15. R15 doesn't use Torso.

0

Zenith_Lord - Thank you! I didn't realize that so I will look into it and try it with an R6 player.

0

change findFirstChild to FindFirstChild and connect to Connect. The former versions of both are deprecated.

0

Also I just realized that Torso.Changed is a typo. I meant to say Torso.CFrame.Changed.

0

No, that would error. ^

0

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.

0

I know this is probably bad but I use humanoid.Changed to check for character movement.

0

I think there is a better way to detect player movement. humanoid.Running.

0

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.

1 answer

✓ Accepted answer

The problem is R15 players don't have a child 'Torso' but both have HumanoidRootPart which I recommend using now of days.

This discussion is preserved as it was. New answers, comments, and votes are closed.