I made a script with 3 things but the model regen part doesn't work? Whats wrong with the regen part? Everything work fine only that not. Someone know how to fix this problem? Thanks ;)
BTW: Its not working anymore the other parts bc the regen is broken but without the regen everyting works fine.
[ Warning don't test the script without changes! Error: Roblox crashes when you touch the brick! ]
Step 1: Making a clone
if (object ~= nil) and (object ~= game.Workspace) then -- Regen model part (Not working)
model = object
backup = model:clone()
end
Step 2: Remove when player touched
while true do -- remove model (Not working)
model:remove()
end
Step 3: Replace back after removed and regens
if (object ~= nil) and (object ~= game.Workspace) then -- place model back (not working)
model = backup:clone()
model.Parent = game.Workspace
model:makeJoints()
end
Full script;
debounce = false -- For respawn when player touches (Player respawn)
object = script.Parent --For regen when player touches
local ting = 0 -- touching
if (object ~= nil) and (object ~= game.Workspace) then -- Regen model part (Not working)
model = object
backup = model:clone()
end
function onTouched(hit)
if ting == 0 then
ting = 1
check = hit.Parent:FindFirstChild("Humanoid")
if check ~= nil then
local user = game.Players:GetPlayerFromCharacter(hit.Parent) -- for player find
local stats = user:findFirstChild("leaderstats") -- for the score
while true do -- remove model (Not working)
model:remove()
end
if hit.Parent:findFirstChild("Humanoid") and debounce == false then --Respawn player part (works)
debounce = true
game.Players:GetPlayerFromCharacter(hit.Parent):LoadCharacter()
end
debounce = false
wait (0.5)
if stats ~= nil then --Score reset (Works)
local cash = stats:findFirstChild("Score")
if cash.Value >= 0 then
cash.Value = cash.Value == 0
end
end
end
ting = 0
end
end
if (object ~= nil) and (object ~= game.Workspace) then -- place model back (not working)
model = backup:clone()
model.Parent = game.Workspace
model:makeJoints()
end
script.Parent.Touched:connect(onTouched)

2 comments
take that while loop away.
Yep thats a little fail of me