How to only fire an event if they are a specific player?

I need help with a remote event for a admin UI. So I want to make a shutdown event but if a hacker can get into the admin UI they can just fire the event. So I only want to fire the event if they are a specific player. But the event still fires even when I change the userId.


Script
--Service--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local AdminEvents = ReplicatedStorage.AdminEvents
local ShutdownEvent = AdminEvents.ShutdownEvent
--

--
ShutdownEvent.OnServerEvent:Connect(function(player, userID)
	if player.UserId == "1507646970" or "339310190" then
		print("Player can fire the event")
	else
		print("Error")
	end
end)
Local Script
--Service--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local userID = Players.LocalPlayer.UserId
local AdminEvents = ReplicatedStorage.AdminEvents
local ShutdownEvent = AdminEvents.ShutdownEvent
--locals--
local ShutdownButton = script.Parent.ShutdownButton
--
ShutdownButton.MouseButton1Click:Connect(function(player, userId)
	ShutdownEvent:FireServer(player, userID)
end)
1 Like

should be

if player.UserId == 1507646970 or player.UserId == 339310190 then

because before: player.UserId == 1507646970 evals to false
then 339310190 evals as truthy

1 Like

Hey, If you don’t mind, can I ask you something?

I used my userId and I double check it and I dosen’t work

go ahead! In the future just ask the question and the person might answer it

Oh ok, I will do that next time. But, are you willing to help me in my post?
Weird movements with the crouch animations
Because legit no one is willing to help me :frowning:

Oh!, userid is a number, not a string
https://developer.roblox.com/en-us/api-reference/property/Player/UserId
so change the strings to numbers

1 Like

HAHA, the video is great. I don’t do animation work

This will always return false because you are trying to compare a number and a string. Also, in the second condition, you forgot to compare that UserId and the player’s UserId in the if statement.

The GuiButton.MouseButton1Click event has no parameters, just use Players.LocalPlayer

You don’t need to pass the player and UserId as arguments because by default the first parameter of the RemoteEvent.OnServerEvent event is the player that fired the RemoteEvent and you can get the UserId with the player’s UserId property.

1 Like