How Can I Change My Currency Required Door So You Have To Buy It?

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)
1 Like

You could try turning cancollide off on the client or set collision groups on the server which might be more reliable

1 Like

turn cancollide off in which part of the script?

Edit: Or did you mean in the properties?

1 Like

When the person buys the door access, turn “CanCollide” off in properties of the door in a localscipt.

1 Like

oh, ok. thanks! ill see if it helps. :smiley:

1 Like

so, i tested it and it still let me through…

1 Like

Your client script should look something like this

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!!."
        Door.CanCollide = false
	end
end)

did you remember to remove the lines where it changes it on the server? (accidentally sent without finishing sorry)

1 Like

OH i didnt put it in the script haha, ill do it now!

1 Like

XD it still lets you through…:confused:

edit: omg im sorry i was wrong, i just tryped something wrong… thanks for the help :smiley:

1 Like

just realized your edit, glad i could help!

1 Like

yeah, sorry i made a mistake! thank you so much!

1 Like