Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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.

0
Do you mean custom ID's, or the roblox ID's made for each roblox account? generalYURASKO 144 — 3y

2 answers

Log in to vote
-2
Answered by 3 years ago
-- 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!

1
this is horribly made Gameplayer365247v2 1055 — 3y
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 } ReaperMr 0 — 3y
Ad
Log in to vote
1
Answered by 3 years ago
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
0
good lord thank you so much, the answer which was accepted is giving me anxiety Wiscript 622 — 3y
0
could you give me the points for helping answer instead of that guy? Gameplayer365247v2 1055 — 3y

Answer this question