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

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

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

the cash script was the problem

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

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

2 comments

0

thank you for answering, but i found out the problem to be my cash script. Thank you once again though!

0

its good yw

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