Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is this tycoon purchase-handling script not working?

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
2
Answered by 7 years ago

One of the objects returned from GetChildren is a model, and models aren't BaseParts,which .Touched works on (http://wiki.roblox.com/index.php?title=API:Class/BasePart/Touched).

0
It still does not work CoolJohnnyboy 121 — 7y
0
What does not work? What did you change? Is there a different error? FrostTaco 90 — 7y
Ad

Answer this question