Hello, I am trying to make a tycoon game and I cannot seem to get a working button that can buy things for the tycoon.
I followed many tutorials such as AlvinBlox and none of them seemed to be able to work with what I had already scripted. Im not sure now to go about moving an item based on the base of the Tycoon becasue if I rotate it or move it the items just go where they are located in replicated storage and not where I move the tycoon to.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CollectionService = game:GetService("CollectionService")
local debounce = true
for _, Button in pairs(CollectionService:GetTagged("Button")) do
local Tycoon = Button.Parent.Parent.Parent
local function onButtonTouched(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
local player = Players:GetPlayerFromCharacter(hit.Parent)
if humanoid and player then
local moneyValue = player.leaderstats.Money
local cost = Button.Price.Value
if moneyValue and moneyValue.Value >= cost and debounce then
debounce = false
moneyValue.Value = moneyValue.Value - cost
local Item = Button.Target.Value
if Item then
local cloned = Item:Clone()
local Script = cloned:FindFirstChild("Script")
if Script then
Script.Enabled = true
end
cloned.Parent = Tycoon.Items
Button:Destroy()
end
debounce = true
else
Button.ErrorBuy:Play()
end
end
end
Button.Top.Touched:Connect(onButtonTouched)
end
Any help would be appriciated!!