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

Continuing on from my earlier question, why does this script only trigger once?

Asked by 2 years ago
game.Players.PlayerAdded:Connect(function()
    repeat
        wait(1.5)
        local clm = game.Workspace.Noob:Clone()
        clm.Parent = game.Workspace
        local cl = clm.Torso
    cl:MoveTo(65,24,-19) --65,24,-19
until
script.Disabled == true
end)


This is for a tycoon-type game, and it should not stop the loop.

1 answer

Log in to vote
1
Answered by 2 years ago

Please include whether an error has occurred or not rather than saying it didn't work.

Using MoveTo()

To answer your question, the script only triggers once because the code inside the loop "errors" causing the script to terminate.

The MoveTo() method is limited to Model or Humanoid types. To fix this, you can either use CFrame to move the model -- or you could use clm as the model and move it as well.

Also, MoveTo()'s first parameter is a Vector3 type. Not providing it will result in another error.

-- example using MoveTo()
local clm = workspace.Noob:Clone() -- clm is a model
clm.Parent = workspace
clm:MoveTo(Vector3.new(65, 24, -19)) -- thus, we can use :MoveTo()

-- example using CFrame
local clm = workspace.Noob:Clone()
clm.Parent = workspace
local cl = clm.Torso -- since Torso is a BasePart, we can set a CFrame to it
cl.CFrame = CFrame.new(Vector3.new(65, 24, -19))

I would also advise you to use a while loop if you don't intend to terminate the loop. Disabling scripts can cause some unintentional behaviors.

0
Thank you but with the MoveTo() example, it does not clone at all now. Using while true do did not do it. I am very confused. blackcatbabydragon 12 — 2y
Ad

Answer this question