✓ Accepted answer
Looking at your code, I think it might be line 12; You are using the 'remove' method. As stated on the WIKI, ':remove()' only reverts the Object's Parent to nil, also, you are not checking if 'Sound' is infact in the PlayerGui, it is just executing that line without checking if it exists or not, thus the Script may break, same with lines 5, and 8.
This can be fixed, let's instead of using remove, let's use the Destroy method, and fix up your code;
local plr = game.Players.LocalPlayer
repeat wait() until plr.Character
function onButton1Down()
plr.Character:MoveTo(Vector3.new(-99.6, 19.5, 23.5))
repeat wait() until game.Workspace.CurrentCamera
local Ncam = game.Workspace.CurrentCamera
Ncam.CameraSubject = plr.Character:WaitForChild("Humanoid")
Ncam.CameraType = "Custom"
wait(0.2)
if plr:FindFirstChild("Backpack") and plr.Backpack:FindFirstChild("CamFix") then
plr.Backpack.CamFix.Disabled = true
plr.Backpack.CamFix:Destroy()
end
script.Parent.Parent.Parent:Destroy()
if plr:FindFristChild("PlayerGui") and plr.PlayerGui:FindFirstChild("Sound") then
plr.PlayerGui.Sound:Stop()
plr.PlayerGui.Sound:Destroy()
end
end
script.Parent.MouseButton1Down:connect(onButton1Down)
Ah, doesn't your code look much better now? :)
As you might have seen in the Code, I have added if then end statements, if then end statements, basically check the condition of something, like it is checking for CamFix and Sound in the code, you may have also noticed I changed your Teleport, yes, I have change it to make it a bit more efficient. :)
The problem of how it could of kept Repeating is because you might have set PlayOnRemove to true, else you might have played it Twice at the same time when executing the code, otherwise I don't know.
Hope this helped!
3 comments
To teleport a character, you should either change the CFrame of their torso, or call MoveTo() on the character model itself. You should also try to tab your code to make it more organized.
:MoveTo is not a valid member of Part.
I think I have fixed the problem, I forgot you can't call the 'MoveTo' method on a 'BasePart' type instance.