Door that costs cash

I am trying to make a script to where if you have enough cash and you touch the door or do the proximity promt it pops a gui, if you press yes on that gui it subtracts the cash and opens up the door for only you and nobody else. This is my script I have to open the gui that isnt working so far

local player = game.Players.LocalPlayer

local price = 250

local gui = game.StarterGui.DoorPurchase.Frame

script.Parent.Touched:Connect(function()
	if player.leaderstats.Cash.Value < price then
		
	else
		gui.Visible = true
	end
end)

local ProximityPrompt = script.Parent.ProximityPrompt
ProximityPrompt.Triggered:Connect(function(player)
	if player.leaderstats.Cash.Value < price then

	else
		gui.Visible = true
	end
end)

This is a local script inside the door.
Also how would I go about when a player clicks yes it opens the door for only them?

1 Like

Hello @Pigioty

Try This:

local player = game.Players.LocalPlayer
local price = 250
local gui = game.StarterGui.DoorPurchase.Frame

script.Parent.Touched:Connect(function()
	if player.leaderstats.Cash.Value >= price then
		gui.Visible = true
         -- Then You should here in you're gui make the function that open the door  (Always In a local Script)
	else
		return false
	end
end)

local ProximityPrompt = script.Parent.ProximityPrompt
ProximityPrompt.Triggered:Connect(function(player)
if player.leaderstats.Cash.Value >= price then
		gui.Visible = true
         -- Then You should here in you're gui make the function that open the door (Always In a local Script)
	else
		return false
	end
end)

1 Like

Nope, My local script is inside of door currently, I got enough cash and everything too no errors either
and the local gui is linked up to the right thing

Then, When the condition is true a Gui Should PopUp gui.Visible = true and inside that gui you should create a local script that if you click “yes” then he removes your money or opens the door (Always on local)

yea but the gui isnt even popping up

Are you sure that the directory of the gui is correct?

Or Are you sure that actualy you’re cash is >= 250?

yep my cash is at 300 and directory is correct

local player = game.Players.LocalPlayer
local price = 250
local gui = game.StarterGui.DoorPurchase.Frame

script.Parent.Touched:Connect(function()
	if player.leaderstats.Cash.Value >= price then
		gui.Visible = true
		-- Then You should here in you're gui make the function that open the door  (Always In a local Script)
	else
		return false
	end
end)

local ProximityPrompt = script.Parent.ProximityPrompt
ProximityPrompt.Triggered:Connect(function(player)
	if player.leaderstats.Cash.Value >= price then
		gui.Visible = true
		-- Then You should here in you're gui make the function that open the door (Always In a local Script)
	else
		return false
	end
end)

what are you trying to trigger of the two? Proximity or Touch?

Also Any Errors on the console?

Since, The condition is correct, im sure of this.

I’ve done both, proximity and touch. No errors

Where is you’re local Script? You Said that it was inside the door, that mean it will probably be on workspace and Local Script don’t run on Workspace.

oh… yea… its in my door… in workspace ;-;

Move you’re local script on StarterPlayerScripts and Re-change all the directory.

I hope I have helped you :+1:
feel free to mak my answer as a solution :grinning:

Let me know if you have others question.

I advise not using a local script. Instead, use a Server Script inside your door and when the proximity prompt is triggered, fire a remote event to a local script in the GUI you want to show. When received, activate the GUI. When the buy button is clicked, send another remote event to a server script to complete the transaction!

Um… It kind of works kind of doesnt, I put it in their and stuff and I checked the frame and it was marked visible this time… but um. It wasn’t visible at all. Its weird to explain

local player = game.Players.LocalPlayer
local price = 250
local gui = game.StarterGui.DoorPurchase.Frame
local door = game.Workspace.Maps.Map1.Door

door.Touched:Connect(function()
	if player.leaderstats.Cash.Value >= price then
		gui.Visible = true
		-- Then You should here in you're gui make the function that open the door  (Always In a local Script)
	else
		return false
	end
end)

local ProximityPrompt = door.ProximityPrompt
ProximityPrompt.Triggered:Connect(function(player)
	if player.leaderstats.Cash.Value >= price then
		gui.Visible = true
		-- Then You should here in you're gui make the function that open the door (Always In a local Script)
	else
		return false
	end
end)

I’m not big brain in fire clients and stuff so…

What do you mean with “It wasn’t visible at all”? Be More specif send photo if that could help you.

1 sec let me rec a video (charss)

This is a good solution however the person in this case is not very expert, so to get started using a local script may be fine then over time he will understand how to improve his code

To use remote events, make one in replicatedstorage

Then use FireClient(plr, moreInfo) to fire to a player
Use FireServer(plr) to fire to the server

True, but in this case, if he wants to subtract money, he will have to use both local and server scripts to communicate between different instances. Leaderstats transactions cannot be made in a local script.