Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why isn't model isn't regenerating after a person leaves the game?

Is there any way to fix this script so that the 'local backup' is removed once the 'backup.Main.Owner.Value' becomes empty? I'm thinking I need some way of checking whether the Owner of the tycoon is still in the game and then to regenerate after they leave but I don't know how I would go about this without lagging up the game.

wait(1)
local model = game.ReplicatedStorage.Tycoon1
local floor = script.Parent.Floor
local backup = model:Clone()
backup.Parent = game.Workspace
backup.PrimaryPart = backup.Baseplate
wait(0.1)
backup:SetPrimaryPartCFrame(CFrame.new(floor.Position))

local function Regen() 
    backup:Destroy()
    wait(1) 
    backup = backup:Clone()
    backup.Parent = script.Parent  
    backup:MakeJoints()
end

while true do 
    wait(1.5) 

    if backup.Main.Owner.Value ~= "" then 
        if not game.Players:FindFirstChild(backup.Main.Owner.Value) then 
            Regen() 

        end 
    end 
end 

Any and all help is appreciated!

1 comment

0

game.Players.PlayerRemoved

1 answer

✓ Accepted answer
wait(1)
local model = game.ReplicatedStorage.Tycoon1
local floor = script.Parent.Floor
local backup = model:Clone()
backup.Parent = game.Workspace
backup.PrimaryPart = backup.Baseplate
wait(0.1)
backup:SetPrimaryPartCFrame(CFrame.new(floor.Position))

local ownerValue = backup.Main.Owner

local function Regen() 
    backup:Destroy()
    wait(1) 
    backup = backup:Clone()
    backup.Parent = script.Parent  
    backup:MakeJoints()
end

ownerValue.Changed:Connect(function()
    if not ownerValue.Value then 
        if not game.Players:FindFirstChild(ownerValue.Value) then 
            Regen() 
        end 
    end 
end 

Changed is a useful event if you want to run code when a object is changed.

This discussion is preserved as it was. New answers, comments, and votes are closed.