I have the script below, My goal is to reset the owner/worker value (which is an object value) when a player leaves. Along with resetting the cash the owner/worker has made. Note: I don’t want the tycoon to reset until both the Owner and Worker value are nil. Currently, my error is getting the script to recognize the owner, I’m not sure if everything under that work properly. Here is the directory of the Tycoon.
The script below is being used in the script “CoreScript” (ignore the Draft)
game.Players.PlayerRemoving:connect(function(player) local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name) local tycoon = script.Parent.Tycoons local assignedowner = tycoon.Name.Owner.Value local assignedworker = tycoon.Name.Worker.Value if assignedowner then print("[SERVER] Owner value found, script is proceeding") end if assignedworker then print("[SERVER] Worker value found, script is proceeding") end if assignedowner == player then tycoon.OwnerCash.Value = 0 assignedowner = nil print("[SERVER] Changed Tycoon Owner value to ".. assignedowner) else warn("[SERVER] Error changing value for assignedowner") end if assignedworker == player then tycoon.WorkerCash.Value = 0 assignedworker = nil print("[SERVER] Changed Tycoon Worker value to ".. assignedworker) else warn("[SERVER] Error changing value for assignedworker") end if cashmoney ~= nil then cashmoney:Destroy() end if assignedowner ~= nil and assignedworker ~= nil then if assignedworker ~= nil then print("worker value = nil") elseif assignedowner ~= nil then print("owner value = nil") --print("OWNER: ".. assignedowner .. " WORKER: " .. assignedworker.."") local backup = tycoonBackups[tycoon.Name]:Clone() tycoon:Destroy() wait(1) backup.Parent = script.Parent.Tycoons end end end)
Thank you for taking the time to read over this and helping in any way you can.