-- Player join/leave handling local function onPlayerAdded(player) loadPlayerData(player) setupLeaderstats(player) -- Spawn player at their current home's spawn point player:LoadCharacter() player.CharacterAdded:Connect(function(character) wait(0.5) local spawnLocation = workspace:FindFirstChild(playerData[player].CurrentHome .. "Spawn") if spawnLocation and spawnLocation:IsA("SpawnLocation") then local hrp = character:FindFirstChild("HumanoidRootPart") if hrp then hrp.CFrame = spawnLocation.CFrame end end end) end
local HOME_INCOMES = { ["Starter Shack"] = 25, ["Cozy Cottage"] = 100, ["Modern Mansion"] = 500, ["Luxury Penthouse"] = 2000, ["Ultimate Palace"] = 10000 } ultimate home tycoon script
local function onPlayerRemoving(player) savePlayerData(player) playerData[player] = nil end ["Cozy Cottage"] = 100
local DataStoreService = game:GetService("DataStoreService") local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local RunService = game:GetService("RunService") ["Modern Mansion"] = 500
-- Give money to player local function giveMoney(player, amount) local data = playerData[player] if data then data.Money = data.Money + amount -- Update leaderstats local leaderstats = player:FindFirstChild("leaderstats") if leaderstats then local cashStat = leaderstats:FindFirstChild("Cash") if cashStat then cashStat.Value = data.Money end end end end
-- Helper: Load player data local function loadPlayerData(player) local userId = player.UserId local success, result = pcall(function() return dataStore:GetAsync(userId) end) if success and result then playerData[player] = { Money = result.Money or STARTING_MONEY, CurrentHome = result.CurrentHome or DEFAULT_HOME, Upgrades = result.Upgrades or { IncomeMultiplier = 1, Automation = false } } else playerData[player] = { Money = STARTING_MONEY, CurrentHome = DEFAULT_HOME, Upgrades = { IncomeMultiplier = 1, Automation = false } } end end