I'm trying to find a way to regenerate a tycoon after the previous owner leaves by checking the owner's name (stored in a StringValue) against the playerlist. The first use of the function works perfectly, resetting the tycoon and clearing the StringValue but on the second loop the Regen function is not called.
Any reasons why this is happening and how to fix??
wait(1)
local model = game.ReplicatedStorage:FindFirstChild("Tycoon1")
local floor = script.Parent
local backup = model:Clone()
backup.PrimaryPart = backup.Baseplate
wait(0.1)
backup:SetPrimaryPartCFrame(CFrame.new(floor.Position))
backup.Parent = game.Workspace
local PlayerName = backup.Main.Owner -- StringValue location
local function Regen()
print("Regeneration Called") -- Does not call on second iteration
backup:Destroy()
wait(0.1)
backup = model:Clone()
backup.Parent = game.Workspace
backup.PrimaryPart = backup:FindFirstChild("Baseplate")
backup:SetPrimaryPartCFrame(CFrame.new(floor.Position))
end
game.Players.PlayerRemoving:Connect(function(Player)
print(Player.Name .. " has left the game.")
if Player.Name == PlayerName.Value then
Regen()
end
end)

4 comments
Check my comment under your other question
No problem! Glad I could help!
Hey I am working on an answer to your question that was removed. I will send you a link to the codeshare here in a bit
never mind you posted the question again in a better way. No need for a codeshare.