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

Why is my LeaderStat door not working? (very confused)

Asked by
tefl0ws 15
5 years ago
Edited 5 years ago

So I was trying to make this Leaderstat Door, but for some reason, it's not working. It worked once in a different Place, but it stopped working. Can someone tell me what I did wrong or help me fix it? Thanks.

(script in part)

    local required_cash = 1000

    local db = true
    script.Parent.Touched:connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") then
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            if player.leaderstats.Cash.Value >= required_cash then
                if db then
                    db = false
                    script.Parent.Transparency = 0.5
                    script.Parent.CanCollide = false
                    wait(3)
                    script.Parent.CanCollide = true
                    script.Parent.Transparency = 0
                    db = true
                end
            end
        end
    end)

(local script)

local required = 1000

    local player = game.Players.LocalPlayer
    local stat = player:WaitForChild("leaderstats"):WaitForChild("Cash")

stat.Changed:connect(function()
        if stat.Value >= required then
        script.Parent.TextLabel.Text = "Door Unlocked!"
    end
end)

(my currency system)

game.Players.PlayerAdded:Connect(function(player)
    local fold = Instance.new("Folder", player)
    fold.Name = "leaderstats"
    local stat = Instance.new("IntValue", fold)
    stat.Name = "Cash"
end)

if someone could please help me, i'd greatly appreciate it thank you once again

2 answers

Log in to vote
1
Answered by
tefl0ws 15
5 years ago

the cash script was the problem

thank you for taking time to answer, i REALLY appreciate it! :D

Ad
Log in to vote
-1
Answered by
Donut792 216 Moderation Voter
5 years ago
Edited 5 years ago
local required_cash = 1000

local db = false
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player.leaderstats.Cash.Value >= required_cash then
            if not db then -- i think this is where you messed up
                db = true
                script.Parent.Transparency = 0.5
                script.Parent.CanCollide = false
                wait(3)
                script.Parent.CanCollide = true
                script.Parent.Transparency = 0
                db = false
            end
        end
    end
end)

-

local required = 1000

    local player = game.Players.LocalPlayer
    local stat = player:WaitForChild("leaderstats"):WaitForChild("Cash")

stat.Changed:Connect(function() -- connect is deprecated
        if stat.Value >= required then
        script.Parent.TextLabel.Text = "Door Unlocked!"
    end
end)

-

game.Players.PlayerAdded:Connect(function(player)
    local fold = Instance.new("Folder") -- think parenting for parameters is deprecated
    fold.Parent = player
    fold.Name = "leaderstats"
    local stat = Instance.new("IntValue")
    stat.Parent = player
    stat.Name = "Cash"
end)

should work. idk havent tested it but try it and let me know

0
thank you for answering, but i found out the problem to be my cash script. Thank you once again though! tefl0ws 15 — 5y
0
its good yw Donut792 216 — 5y

Answer this question