I was creating a tycoon game, when I stubled across this error
It started when I created the tycoon game, but I thought nothing of it until right now.
Because when I inserted a button, made the model, I placed the Button in this folder
Then I placed the model in this folder.
So, inside the button there are 3 values.
Dependancy, Item and the Price.
What the Dependancy does is if you buy an item, then that button would appear, so its not just a load of buttons everywhere.
In the items folder, you would put the name of the model, ex: Dropper1.
The price is what you would expect, obviously it is the price of the item.
Those are the 3 main values, in every button.
So, my problem is that when you spawn in, either the model or the button is there.
Those items were supposed to be in the game later on.
And Iâm pretty sure itâs not with the dependancy because i checked those items, and they were fine.
This is the main script located in the âScriptsâ folder.
Blockquoteâ Variables â
local TycoonModel = script.Parent.Parent
local Items = {}
local BoughtItems = TycoonModel:FindFirstChild(âBoughtItemsâ)
local Buttons = TycoonModel:FindFirstChild(âButtonsâ)
local DropperParts TycoonModel:FindFirstChild(âDropperPartsâ)
local MainItems = TycoonModel:FindFirstChild(âMainItemsâ)
local Scripts = TycoonModel:FindFirstChild(âScriptsâ)
local Values = TycoonModel:FindFirstChild(âValuesâ)
â Owner Functions â
MainItems.OwnerDoor.MainDoor.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild(âHumanoidâ) and Values.OwnerValue.Value == nil then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Player:FindFirstChild(âOwnsTycoonâ).Value == false then
Values.OwnerValue.Value = Player
Player:FindFirstChild(âOwnsTycoonâ).Value = true
MainItems.OwnerDoor.MainDoor.SurfaceGui.TextLabel.Text = tostring(Values.OwnerValue.Value)âŚ" Tycoon"
end
end
end)
â Buying Functions â
for i,v in pairs(Buttons:GetChildren()) do
local NewItem = BoughtItems:FindFirstChild(v.Item.Value)
if NewItem ~= nil then
Items[NewItem.Name] = NewItem:Clone()
NewItem:Destroy()
else
v.ButtonPart.Transparency = 1
v.ButtonPart.CanCollide = false
v.ButtonPart.BillboardGui.Frame.Visible = false
end
if v:FindFirstChild(âDependencyâ) then
coroutine.resume(coroutine.create(function()
v.ButtonPart.Transparency = 1
v.ButtonPart.CanCollide = false
v.ButtonPart.BillboardGui.Frame.Visible = false
if BoughtItems:WaitForChild(v.Dependency.Value, 100000) then
v.ButtonPart.Transparency = 0
v.ButtonPart.CanCollide = true
v.ButtonPart.BillboardGui.Frame.Visible = true
end
end))
end
v.ButtonPart.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild(âHumanoidâ) then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Values.OwnerValue.Value == Player then
if v.ButtonPart.CanCollide == true and v.ButtonPart.Transparency == 0 then
if Player:WaitForChild(âleaderstatsâ).Cash.Value >= v.Price.Value then
Player.leaderstats.Cash.Value -= v.Price.Value
Items[v.Item.Value].Parent = BoughtItems
v:Destroy()
end
end
end
end
end)
end
â Cash Functions â
local Debounce = false
MainItems.CashButton.ButtonPart.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild(âHumanoidâ) then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Values.OwnerValue.Value == Player then
if Debounce == false then
Debounce = true
if game:GetService(âMarketplaceServiceâ):UserOwnsGamePassAsync(Player.UserId,24922437) then
Player:WaitForChild(âleaderstatsâ).Cash.Value += Values.CashValue.Value * 2
wait()
Values.CashValue.Value = 0
wait(1)
Debounce = false
else
Player:WaitForChild(âleaderstatsâ).Cash.Value += Values.CashValue.Value
wait()
Values.CashValue.Value = 0
wait(1)
Debounce = false
end
end
end
end
end)
while wait() do
MainItems.CashButton.ScreenPart.SurfaceGui.TextLabel.Text = Values.CashValue.Value
end
There are more folders called:
Mainitems
Values
The Mainitems folder works like this:
If you insert a Model inside of the folder, then you will spawn with it in your tycoon.
The values folder, is where all of the values are stored.
There is also a script called âleaderstatsâ
Located in ServerScriptService.
This is the script.
Blockquotegame.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new(âFolderâ, Player)
leaderstats.Name = âleaderstatsâ
local Cash = Instance.new(âNumberValueâ, leaderstats)
Cash.Name = âCashâ
Cash.Value = 0
local OwnsTycoon = Instance.new(âBoolValueâ, Player)
OwnsTycoon.Name = âOwnsTycoonâ
OwnsTycoon.Value = false
end)
If you need any more information, please tell me.