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

Why are these lines either not running or running twice?

Asked by 4 years ago

I am making a tycoon game that saves your data. I have saved and loaded the data but now when someone claims their tycoon, the code that looks through what the player owns doesn't work very well.

line 37 is either not running or is being overrited by line 62

for i, v in pairs(player.PurchaseFolder:GetChildren()) do
                for i, t in pairs(script.Parent.Parent.Buttons:GetChildren()) do
                    if v.Value == t.Name then
                        for i, o in pairs(script.Parent.Parent.Buyable:GetChildren()) do
                            local str = string.split(t.Name," ")
                            local str2 = string.split(o.Name, " ")
                            if str[2] ~= "|" then
                                print("1")
                                if str2[1] == str[1] and str2[2] == str[2] then
                                    print(str[1]..", "..str2[1]..". "..str[2]..", "..str2[2])
                                    print("2")
                                    if str[1] == "Lights" and str[2] == str2[2] then
                                        print("3")
                                        for i, child in ipairs(o:GetChildren()) do
                                            if child.ClassName == 'Model' then
                                                for i, lights in ipairs(child:GetChildren()) do
                                                    if lights.ClassName == 'Part' then
                                                        lights.Transparency = 0
                                                        lights.CanCollide = true
                                                        for i, pointlight in ipairs(lights:GetChildren()) do
                                                            if pointlight.ClassName == "PointLight" then
                                                                pointlight.Brightness = 1.24
                                                            end
                                                        end
                                                    end
                                                end
                                            end
                                        end
                                        t:Destroy()
                                    end
                                    if str[1] == "Walls" and str2[1] == "Walls" and str[2] == str2[2] then
                                        print("4")
                                        for i, child in ipairs(o:GetChildren()) do
                                            if child.ClassName == 'Part' then
                                                if child.Name ~= 'DropLocation' then
                                                    if child.Name == 'Glass' then
                                                        child.Transparency = 0.4
                                                    else
                                                        child.Transparency = 0
                                                    end
                                                end
                                                child.CanCollide = true
                                            end
                                        end
                                        t:Destroy()
                                    end
                                    if str[1] == "Upgrade" and str[2] == str2[2] then
                                        print("5")
                                        for i, child in ipairs(o:GetChildren()) do
                                            if child.ClassName == 'Part' then
                                                if child.Name ~= 'DropLocation' then
                                                    child.Transparency = 0.65
                                                    child.UpgradeScript.Disabled = false
                                                end
                                                child.CanCollide = false
                                            end
                                        end
                                        t:Destroy()
                                    end
                                end
                            else
                                for i, child in ipairs(o:GetChildren()) do
                                    if child.ClassName == 'Part' then
                                        if child.Name ~= 'DropLocation' then
                                            child.Transparency = 0
                                        end
                                        child.CanCollide = true
                                    end
                                end
                                if script.Parent.Parent.Buyable:FindFirstChild(o.Name):FindFirstChild('Activated') then
                                    script.Parent.Parent.Buyable:FindFirstChild(o.Name):FindFirstChild('Activated').Value = true
                                end
                                if t:FindFirstChild("Unlocks") then
                                    for i, button in ipairs(t.Unlocks:GetChildren()) do
                                        button.Value.Head.Transparency = 0
                                        button.Value.Head.CanCollide = true
                                    end
                                end
                                t:Destroy()
                            end
                        end
                    end
                end
            end

1 answer

Log in to vote
0
Answered by 4 years ago

I think you should be using datastores for this saving function?

Ad

Answer this question