Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is this tycoon purchase-handling script not working?

Hi all,

I'm trying to create a centralized tycoon script that would manage all buttons, purchases, and items in one script. However, the script doesn't work whatsoever, and output didn't give me much.

Can someone please help me?

Here's the script (Output will be posted below the script):

local new_Objects = {}
local Owner = script.Parent.Parent:WaitForChild("OwnerName")

for a,b in pairs(script.Parent:GetChildren()) do
	if b:IsA("Model") then
		local Ignore = script.Parent.Parent:WaitForChild("Ignore")
		if Ignore.Value == true then 
			for c,d in pairs(b.Items:GetChildren()) do
				local Stuff = script.Parent.Parent:WaitForChild("Items")
				new_Objects[Stuff[d.Value].Name] = Stuff[d.Value]:Clone()
				Stuff[d.Value]:Destroy()
			end
			for e,f in pairs(b.new_Buttons:GetChildren()) do
				local Stuff = script.Parent
				new_Objects[Stuff[f.new_Buttons.button_Name.Value].Name] = Stuff[f.new_Buttons.button_Name.Value]:Clone()
				Stuff[f.new_Buttons.button_Name.Value]:Destroy()
			end
		end
		function onTouch(hit)
			local check = hit.Parent:FindFirstChild("Humanoid")
			if check ~= nil then
				if hit.Parent.Name == Owner.Value then
					local user = game.Players:GetPlayerFromCharacter(hit.Parent)
					local stats = user:findFirstChild("leaderstats")
					if stats ~= nil then
						local Items = b:WaitForChild("Items")
						local newB = b:WaitForChild("new_Buttons")
						local Cost = b:WaitForChild("Cost")
						local Currency = b:WaitForChild("Currency")
						if stats[Currency.Value].Value >= Cost.Value then
							stats[Currency.Value].Value = stats[Currency.Value].Value - Cost.Value
							for g,h in pairs(Items:GetChildren()) do
								new_Objects[h.Value].Parent = script.Parent.Parent.Purchased
							end
							for i,j in pairs(newB:GetChildren()) do
								new_Objects[j.Value].Parent = script.Parent.Parent.Purchased
							end
						end
					end
				end	
			end
		end
		b.Touched:connect(onTouch) 
	end	
end

Output: Touched is not a valid member of Model

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.