Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can i make MouseButton1Click work for only a specific player ID? (or more)

Hey there, so i'm making a button, if you click it you will recieve a pop up. But i want this to work for only one (or a couple) players. How can i do this? (Be sure that it works with player ID's)

Also please be specific.

1 comment

0

Do you mean custom ID's, or the roblox ID's made for each roblox account?

2 answers

✓ Accepted answer
-- Var --
local Player = game.Players.LocalPlayer
local Button = script.Parent.Button -- Change this to your button
local Player1 = 000000000 -- Change these to your ids 
local Player2 = 000000000
local Player3 = 000000000
local Player4 = 000000000
local Player5 = 000000000


local function listed()
	print("You are on the list!")
	-- Do something if the player is on the list
end

local function notlisted()
	print("You are not on the list!")
	-- Do something if the player is not on the list
end
	
-- Script --
Button.MouseButton1Click:Connect(function()
	if Player.UserId == Player1 then
		listed()
	elseif Player.UserId == Player2 then
		listed()
	elseif Player.UserId == Player3 then
		listed()
	elseif Player.UserId == Player4 then
		listed()
	elseif Player.UserId == Player5 then
		listed()
	else --Add more elseif if you have more player ids
		notlisted()
	end
end)

This isn't the most efficient script but its the first thing that came to mind, hope it helps!

2 comments

1

this is horribly made

0

why dont you use tables? idk how to use them but im pretty sure it would make your script look much cleaner than this lol Example: local ids = {000000000 ,000000000 ,000000000 ,000000000 }

local ids = {}--put some ids in here and seperate them with a comma
local player = game.Players.LocalPlayer

Button.MouseButton1Click:Connect(function()
	if table.find(ids,player.UserId) then
		--you got it from here
	end
end

2 comments

0

good lord thank you so much, the answer which was accepted is giving me anxiety

0

could you give me the points for helping answer instead of that guy?

This discussion is preserved as it was. New answers, comments, and votes are closed.