I need help to fix in my tycoon once a player leaves without claiming a tycoon. My Code :
game:GetService("Teams")
local Players = game:GetService("Players")
function GetTycoonFromPlayer(Player)
for i, v in pairs(script.Parent.Tycoons:GetChildren()) do
if v:IsA("Model") then
if v.Owner.Value == Player then
return v
end
end
end
return nil
end
local tycoonBackups = {}
for i, v in pairs(script.Parent.Tycoons:GetChildren()) do
tycoonBackups[v.Name] = v:Clone()
if v:IsA("Model") then
local Team = Instance.new("Team", game.Teams)
Team.Name = v.Name
Team.AutoAssignable = false
Team.TeamColor = v.TeamColor.Value
end
end
Players.PlayerAdded:Connect(function(Player)
local PlayerCash = Instance.new("NumberValue", game.ServerStorage.PlayerMoney)
PlayerCash.Name = Player.Name
local PlayerOwnsTycoon = Instance.new("BoolValue", PlayerCash)
PlayerOwnsTycoon.Name = "OwnsTycoon"
end)
Players.PlayerRemoving:Connect(function(Player)
local PlayerCash = game.ServerStorage.PlayerMoney:FindFirstChild(Player.Name)
if PlayerCash ~= nil then
PlayerCash:Destroy()
end
local tycoon = GetTycoonFromPlayer(Player)
local backup = tycoonBackups[tycoon.Name]:Clone()
wait(1)
backup.Parent = script.Parent.Tycoons
end)

2 comments
Is there an error and what is not happening when the player leaves?
Error in question name.