Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by
thesit123 509 Moderation Voter
6 years ago

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)

Ad

Answer this question