Hello, So in my game, i have a door that you need a certain amount of Coins to enter. and it works fine but sometimes when theres someone with the right amount of coins and someone without the right amount of coins standing at the door, it somehow lets the player without enough coins through.
Can someone please help me fix that and make it so when you walk up to the door, a gui pops up and asks you if you’d like to buy it? and so it saves?
if you can that’d be awesome! thanks!
and also theres 2 different codes for it,
this one goes in a regular script inside the part/door.
local required_coins = 250
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.Coins.Value >= required_coins 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.5
db = true
end
else
script.Parent.CanCollide= true
end
end
end)
and this one goes in a local script in a surface gui in starter gui.
local required = 250
local player = game.Players.LocalPlayer
local stat = player:WaitForChild("leaderstats"):WaitForChild("Coins")
stat.Changed:connect(function()
if stat.Value >= required then
script.Parent.TextLabel.Text = "Beach World Unlocked!!."
end
end)