Check if player is holding a keycard

Hello !
I’m starting the omega watrhead button, and I got this script, in a ProximitryPrompt for the card reader :

local prox = script.Parent
local part = script.Parent.Parent
local Players = game.Players.LocalPlayer

prox.Triggered:Connect(function()
	if Players.Character:FindFirstChild("[SCP] Card-L5") or Players.Character:FindFirstChild("[SCP] Alpha-1") then
		print("Opening button")
		game.ReplicatedStorage.OmegaWarheadButton:FireServer()
	end
end)

But it doesn’t work.
Since this is suppose to trigger a

Nuclear bomb

Only people with the highest rank of card (L5) have access to this. How can I do it?

Just use the return of Triggered which returns the player who triggered the event to know the player who triggered it and check them. Put this in a server script in the right area corresponding to your part and proximity prompt

local prox = script.Parent
local part = script.Parent.Parent

prox.Triggered:Connect(function(player)
	if player.Character:FindFirstChild("[SCP] Card-L5") or player.Character:FindFirstChild("[SCP] Alpha-1") then
		--OmegaWarheadButton Event code here
	end
end)
2 Likes

Make sure you check that the player has the card equipped from the server aswell to prevent exploiting…

something like:

local Character = Player.Character
if Character then
	local Tool = Character:FindFirstChildOfClass("Tool")
	if Tool then
		if Tool.Name == "[SCP] Card-L5" then
			-- ...
		end
	end
end

Card.rbxl (22.6 KB)

3 Likes

Well I know that when a player have a tool equipped, it is parented to his character, so I wanted to use FIndFirstChild to check if he equipped the required card

1 Like

It is also parented to the Backpack if the player doesn’t have the tool in their hand. I also just saw that they are two different cards and I see what you are trying to do. My apologies for that mistake. Try using the player parameter in the Triggered event though instead of LocalPlayer.

local prox = script.Parent
local part = script.Parent.Parent

prox.Triggered:Connect(function(player)
    --code here
end)

Edit: Also instead of having to fire to the server, you can make this a (server)script to prevent exploiting and try to move the code from the OmegaWarheadButton event over to this. Something that I think EmbatTheHybrid forgot to mention.

2 Likes

Imma try, thanks.
I just used LocalScript so it’s easier to Use game.Players.LocalPlayer

That is the problem, people can exploit through local scripts. You are going to want a (server)script to prevent that and use the player parameter from the triggered event.

Oops! Thanks for pointing that out!

1 Like

Made a simple code out of yours @EmbatTheHybrid thanks !
Here you go (I wasn’t focused on Tween, just see if the glass get destroyed)

local prox = game.Workspace.OmegaWarhead.Union.ProximityPrompt

prox.Triggered:Connect(function(player)
	if player.Character:FindFirstChild("[SCP] Card-L5") or player.Character:FindFirstChild("[SCP] Alpha-1") then
		print("Opening button")
		game.Workspace.OmegaWarhead.Union:Destroy()
	end
end)
1 Like

Anytime! if you have anymore issues don’t be afraid to make another post!