local objects = {} local teamcolor = BrickColor.new(script.Parent.Name) local…
- User
local objects = {} local teamcolor = BrickColor.new(script.Parent.Name) local TycoonModel = script.Parent
TycoonModel:WaitForChild("Buttons") TycoonModel:WaitForChild("Purchases")
local function getPlayerFromHit(hit) return game.Players:GetPlayerFromCharacter(hit.Parent) end
local function playerOwnsTycoon(player) return player and TycoonModel.Owner.Value == player end
local function characterIsAlive(character) local humanoid = character:FindFirstChild("Humanoid") return humanoid and humanoid.Health > 0 end
local function getCashStorage(player) return game.ServerStorage.MoneyStorage:FindFirstChild(player.Name) end
TycoonModel.Essentials.Collector.Touched:Connect(function(hit) local cash = hit:FindFirstChild("Cash") if cash then TycoonModel.Cash.Value += cash.Value game.Debris:AddItem(hit, 0) end end)
TycoonModel.Essentials.Giver.Touched:Connect(function(hit) local player = getPlayerFromHit(hit) if player and playerOwnsTycoon(player) and characterIsAlive(hit.Parent) then local cashStorage = getCashStorage(player) if cashStorage then cashStorage.Value += TycoonModel.Cash.Value TycoonModel.Cash.Value = 0 end end end)
for _, button in TycoonModel.Buttons:GetChildren() do local head = button:FindFirstChild("Head") if head then local objectName = button.Object and button.Object.Value local purchaseObject = objectName and TycoonModel.Purchases:FindFirstChild(objectName) if purchaseObject then objects[objectName] = purchaseObject:Clone() purchaseObject:Destroy() else warn("Button: " .. button.Name .. " is missing its object and has been removed.") head.CanCollide = false head.Transparency = 1 end
if button:FindFirstChild("Dependency") then head.CanCollide = false head.Transparency = 1 coroutine.wrap(function() while not TycoonModel.PurchasedObjects:FindFirstChild(button.Dependency.Value) do task.wait() end head.CanCollide = true head.Transparency = 0 end)() end head.Touched:Connect(function(hit) local player = getPlayerFromHit(hit) if player and head.CanCollide and playerOwnsTycoon(player) and characterIsAlive(hit.Parent) then local cashStorage = getCashStorage(player) if cashStorage and cashStorage.Value >= button.Price.Value then cashStorage.Value -= button.Price.Value head.Transparency = 1 head.CanCollide = false objects[objectName].Parent = TycoonModel.PurchasedObjects end end end) endend
This script is inside workspace > Tycoons > [every tycoon Model in here] > PurchaseHandler(the script). modify it to be used in ServerScriptService and handle all the tycoon Models inside Tycoons.
- Assistant
- User
calling purchaseObject:Destroy() gives out alot of errors. clone them in ServerStorage instead. dont give me the whole script, just the part that is relevant.
- Assistant
Certainly! You should adjust the part where
purchaseObjectis cloned and destroyed to handle storing these clones inServerStorageinstead. Here's the relevant part with the changes:local ServerStorage = game:GetService("ServerStorage") local tycoonObjectsFolder = ServerStorage:WaitForChild("TycoonObjects") -- Ensure there is a folder in ServerStorage for storing tycoon objects if not tycoonObjectsFolder then tycoonObjectsFolder = Instance.new("Folder") tycoonObjectsFolder.Name = "TycoonObjects" tycoonObjectsFolder.Parent = ServerStorage end -- Replace this block: -- tycoonObjects[objectName] = purchaseObject:Clone() -- purchaseObject:Destroy() -- With this block: if not tycoonObjectsFolder:FindFirstChild(objectName) then local clonedObject = purchaseObject:Clone() clonedObject.Parent = tycoonObjectsFolder end tycoonObjects[objectName] = tycoonObjectsFolder:FindFirstChild(objectName)