Tycoon script it doesn't work and it doesn't show any error

Hey, I have been debugging for hours and I still don’t understand why my script doesn’t work…

Also the problem is in the buying functions part
Here is the script:

--Variables

local TycoonModel = script.Parent.Parent
local items = {}

local Boughtitems = TycoonModel:FindFirstChild("BoughtItems")
local Buttons = TycoonModel:FindFirstChild("Buttons")
local Fishermans = TycoonModel:FindFirstChild("Fishermans")
local MainItems = TycoonModel:FindFirstChild("Mainitems")
local Scripts = TycoonModel:FindFirstChild("Scripts")
local Values = TycoonModel:FindFirstChild("Values")

--Owner thing

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)
		Values.OwnerValue.Value = player
		MainItems.OwnerDoor.MainDoor.SurfaceGui.TextLabel.Text = player.DisplayName.."'s Tycoon"
		MainItems.OwnerDoor.MainDoor.Transparency = 0.35
	end
end)

--Money Functions

local debounce = false

MainItems.CashCollector.Part.Pad.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
				player:WaitForChild("leaderstats").Money.Value += Values.CashValue.Value
				wait()
				Values.CashValue.Value = 0
				wait(1)
				debounce = false
			end
		end
	end
end)

while wait() do
	MainItems.CashCollector.SurfaceGui.TextLabel.Text = Values.CashValue.Value
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
	end
	
	if v:FindFirstChild("Dependency") then
		coroutine.resume(coroutine.create(function()
			v.ButtonPart.Transparency = 1
			v.ButtonPart.CanCollide = false
			if Boughtitems:WaitForChild(v.Dependency.Value,1000000)then
				v.ButtonPart.Transparency = 0
				v.ButtonPart.CanCollide = 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").Money.Value >= v.Price.Value then
						player.leaderstats.Money.Value -= v.Price.Value
						items[v.item.Value].Parent = Boughtitems
						v:Destroy()
					end
				end
			end
		end
	end)
	
end

image

1 Like

image

Hey, I’d recommand adding print() statements to your code…

I tried doing that and it still didn’t work

It isn’t supposed to make the script work but to know where the scripts fails

ok, where do you think i should add them? I only did at the start and end

there is a tutorial on where to use them here

I just realized, it doesn’t detect the touch

Nevermind, i had to put the script under the owner functions line

1 Like