Certain Amount Of Money Door

  1. What do you want to achieve?
    I’m trying to make a door that will only let players through if they have $2,000

  2. What is the issue?
    The script isn’t working

  3. What solutions have you tried so far?
    I tried adding a print statement to the part where the part is touched but nothing printed in the output.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Plr)
	local cashValue = Plr.leaderstats:WaitForChild("Cash")
	
	script.Parent.Touched:Connect(function(Touch)
		if Touch.Parent:FindFirstChild("Humanoid") ~= nil then
			if cashValue.Value >= 2000 then
				for i = 0, 1, -0.1 do
					script.Parent.Transparency = i
					wait(0.1)
				end
				wait(1)
				for i = 1, 0, 0.1 do
					script.Parent.Transparency = i
					wait(0.1)
				end
			end
		else
			print("not enough")
		end
	end)
end)
1 Like

I am not sure but I think it would be this, if a number value is in the local player

local plr = game:GetService(“Players”)

script.Parent.Touched:Connect(function()
if plr.Cash.Value <= 2000 then
script.Parent.CanCollide = false
script.Parent.Transparency = 0.5
wait(5)
script.Parent.CanCollide = true
script.Parent.Transparency = 0
end
end

1 Like

That wouldn’t get the player. That would get the player service.

1 Like

Are you trying to make it so it opens when the player touches it and then it closes or it stays open?

1 Like

If you’re trying to make it so it opens when the cash is over 2000, it could glitch if the player rejoins with 1000 cash or something.

1 Like

I’m trying to make it so that if they have that certain amount the door opens long enough to let the in and then close.

If it opens for a bit to let a player in, it could let other players who don’t meet the requirements in.

1 Like

I have a DataStore so it would save the amount.

Can the player spend the cash? If yes do they need to buy access to the door?

1 Like

At the moment, the players don’t use the cash they only earn it.

Are you struggling to make the door open? You could accomplish this with a LocalScript. I experimented with 2 players locally:


On the left: I clicked that button to get rid of that door
On the right: I didn’t click it and I can’t get through.

1 Like

Have you tried getting the player by who touched the part? You can use :GetPlayerFromCharacter() like so:
script.Parent.Touched:Connect(function(Touch) if Touch.Parent:FindFirstChild("Humanoid") ~= nil then local plr = game:GetService("Players"):GetPlayerFromCharacter(Touch.Parent)
Edit: apologies for the improper indentation i’ll try to fix it.

1 Like

Well I want to make it so that they can just walk through and not have to press a button.

No Collide the part for them on the client.

1 Like

I was just using the button click as an example. I’ll try to get a script for you.

1 Like

Set the part property “CanCollide” to false on the players client and they can walk through.

1 Like

I totally forgot about :GetPlayerFromCharacter. It’s working now thanks!

I was in the middle of writing a script too lol. Nevermind I guess.

1 Like

No problem, glad to have helped.

1 Like

I mean just incase, here’s my script:

local Money = game.Players.LocalPlayer.leaderstats:WaitForChild("Cash")

while true do
	wait(1)
	if Money.Value >= 2000 then
		game.Workspace.DoorPart.CanCollide = false
		game.Workspace.DoorPart.Transparency = 1
		wait(1)
		script:Destroy()
	end
end

Have a nice day, even if this didn’t help.

1 Like