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
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