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

Script only works once, is broken when used on a moving object, but doesn't give error messages?

Hello,

I have a script, that makes you stick to a part for 2 seconds However, if you've done it once, it stops working And if it's used on a moving object, you don't stick to the object anymore I don't get any errors however

Help me please

game.Players.PlayerAdded:Connect(function(p)
      local char = game.Workspace:WaitForChild(p.Name)
      local part = script.Parent -- part
      local time = 2 -- amount of time
     local place = CFrame.new(part.Position) -- Where you want the player to go on touched
    repeat wait(1) time = time - 1 char.Torso.CFrame = place until time < 1
end)

If you could help, thanks

+I'm really bad with scripts that are activated on touch of script.parent so how do I do that?

1 answer

This isn't an impossible task to do. All you have to do is: Instead of putting

char.Torso.CFrame = place,

try

char.Torso.CFrame = CFrame.new(part.Position)

so it's going to get the new CFrame of the part every second.

game.Players.PlayerAdded:Connect(function(p)
	local char = game.Workspace:WaitForChild(p.Name)
	local part = script.Parent -- part
	local time = 2 -- amount of time
	repeat
		wait(1)
		time = time - 1
		char.Torso.CFrame = CFrame.new(part.Position)
	until time < 1
end)

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