What do I want to achieve?
I want a checkpoint that if deleted will stop working and the player will spawn back at the spawn again
What is the issue?
even when the part WITH the script is deleted the player still spawns at the same position
What solutions have you tried so far?
I could not find any solutions
local spawn = script.Parent
spawn.Touched:connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.CharacterAdded:connect(function(character)
wait()
character:WaitForChild("HumanoidRootPart").CFrame = script.Parent.CFrame + Vector3.new(0, 4, 0)
end)
end
end)
local spawn = script.Parent
local connection
connection = spawn.Touched:connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.CharacterAdded:connect(function(character)
wait()
character:WaitForChild("HumanoidRootPart").CFrame = script.Parent.CFrame + Vector3.new(0, 4, 0)
connection:Disconnect()
end)
end
end)
I’m not sure when you want the script to stop working so you’ll have to move the connection:Disconnect() around.
Destroying a script on the client doesn’t stop it from running in the server, it’ll continue running. You should try .Disabled instead or disconnect like @1000knives said.
Hey there, thanks for the info but even with disconnect it wont work. I want to disconnect it when the parent of the script is nil
local spawn = script.Parent
local connection
connection = spawn.Touched:connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.CharacterAdded:connect(function(character)
wait()
if script.Parent then
character:WaitForChild("HumanoidRootPart").CFrame = script.Parent.CFrame + Vector3.new(0, 4, 0)
else
connection:Disconnect()
end
end)
end
end)