What do you want to achieve? Making a script that clone RoadModel to CloneTo Position and delete the old Road (RoadModel)
What is the issue? The script work only 1 time
What solutions have you tried so far? Check the script and see if there is any issue and see the output if there is any errors but I didn’t saw anything wrong
This is the script
local player = game.Players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats2")
local Dif = leaderstats:WaitForChild("Dif")
local part = script.Parent
part.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Clone = game.Workspace.RoadModel:Clone()
local NewPosition = CFrame.new(game.Workspace.RoadModel.CloneTo.Position)
Clone:SetPrimaryPartCFrame(NewPosition)
Clone.Parent = workspace
Dif.Value = Dif.Value -1
script.Disabled = true
wait(1)
part.Parent:Destroy()
workspace.Obstacles:Destroy()
local Obstacles = Instance.new("Folder", workspace)
Obstacles.Name = "Obstacles"
script.Disabled = false
print("Done")
end)
end)
Uh, I don’t know if I’m just seeing it incorrectly, but are you disabling the script mid-way through? I think that is the issue. Additionally, you are destroying the parent itself which deletes all children as well, including the script.
I disable the script in the mid to avoid spam + the script destroy the road and do the other things (one time only) and if i destroy the road and destroy the script its clone so its come back
local Players = game:GetService("Players")
local Part = script.Parent
local Debounce = true
Players.PlayerAdded:Connect(function()
Part.Touched:Connect(function(hit)
local Player = Players:GetPlayerFromCharacter(hit.Parent)
if Player and Debounce then
Debounce = not Debounce
local Leaderstats = Player:WaitForChild("leaderstats2")
local Dif = Leaderstats:WaitForChild("Dif")
local Clone = workspace.RoadModel:Clone()
local NewPosition = CFrame.new(workspace.RoadModel.CloneTo.Position)
Clone:SetPrimaryPartCFrame(NewPosition)
Clone.Parent = workspace
Dif.Value -= 1
task.wait(1)
Part.Parent:Destroy()
workspace.Obstacles:Destroy()
local Obstacles = Instance.new("Folder")
Obstacles.Name = "Obstacles"
Obstacles.Parent = workspace
Debounce = not Debounce
print("Done")
end
end)
end)
local Players = game:GetService("Players")
local Part = script.Parent
local Debounce = true
Part.Touched:Connect(function(hit)
local Player = Players:GetPlayerFromCharacter(hit.Parent)
if Player and Debounce then
Debounce = not Debounce
local Leaderstats = Player:WaitForChild("leaderstats2")
local Dif = Leaderstats:WaitForChild("Dif")
local Clone = workspace.RoadModel:Clone()
local NewPosition = CFrame.new(workspace.RoadModel.CloneTo.Position)
Clone:SetPrimaryPartCFrame(NewPosition)
Clone.Parent = workspace
Dif.Value -= 1
task.wait(1)
Part.Parent:Destroy()
workspace.Obstacles:Destroy()
local Obstacles = Instance.new("Folder")
Obstacles.Name = "Obstacles"
Obstacles.Parent = workspace
print("Done")
end
end)
local make = function()
local player = game.Players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats2")
local Dif = leaderstats:WaitForChild("Dif")
local part = script.Parent
part.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Clone = game.Workspace.RoadModel:Clone()
local NewPosition = CFrame.new(game.Workspace.RoadModel.CloneTo.Position)
Clone:SetPrimaryPartCFrame(NewPosition)
Clone.Parent = workspace
Dif.Value = Dif.Value -1
script.Disabled = true
wait(1)
part.Parent:Destroy()
workspace.Obstacles:Destroy()
local Obstacles = Instance.new("Folder", workspace)
Obstacles.Name = "Obstacles"
script.Disabled = false
print("Done")
end)
end)
end
Make sure to put it into a function so you can use it more than once!
If you want to make it repeat constantly, put the function into a loop like this:
You can end the loop by using “break” anywhere inside, which will force it to yeild.
if you want to run this in the background you can also put it inside a coroutine,
Heres some info about them if you’re confused: