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

How to whitelist a tool to a certain Player?

Asked by
G0ZZEN 17
5 years ago

So i tried to whitelist the tool for a certain player so, when someone equips it and he's not whitelisted then it will destroy the tool, but if they are whitelisted then it will not be destroyed.

My current progress so far:

1game.Players.PlayerAdded:connect(function(plr)
2if plr.name == "Thatisnotmyrealuser" then
3    wait()
4else
5    script.parent:destroy()
6end
7end)

3 answers

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

You can just clone it to their StarterGear if they are whitelisted.

01-- dictionary with names lowercased
02local WhiteList = {['azarth'] = true, ['you'] = true}
03-- location of tool
04local Tool = script:WaitForChild("Tool")
05 
06local function PlayerJoined(Player)
07    -- if whitelisted
08    if WhiteList[Player.Name:lower()] then
09    -- clone tool to StarterGear
10        Tool:Clone().Parent = Player:WaitForChild('StarterGear')
11    end
12end
13 
14-- On join
15game.Players.PlayerAdded:Connect(PlayerJoined)
16 
17-- Players not caught by event
18for i,v in pairs ( game.Players:GetPlayers()) do
19    PlayerJoined(v)
20end
0
Not exactly what i intended, but it has the same effect in the end, thanks for helping! G0ZZEN 17 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

i have a pretty simple script but it works. what this script does is, when a player picks up a tool they by default equip the tool. so when the player equips the tool it checks if the players name is in a whitelist table or not if it is then it prints "whitelisted" elseif they are not in the whitelist table it destroys itself.

01local whitelist = {"YourUser", "FriendsUser"} --add the whitelist users here
02 
03script.Parent.Equipped:Connect(function()
04    local char = script.Parent
05    if char.Name == whitelist then
06        print("whitelisted")
07    elseif char.Name ~= whitelist then
08        script.Parent:Destroy()
09    end
10end)

just place this in a serverscript inside of your tool. hope this helped you :)

Log in to vote
0
Answered by
raid6n 2196 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

First, we need to see if the player is not “Theisnotmyrealuser”

1game.Players.PlayerAdded:connect(function(plr)
2if not plr.name == "Thatisnotmyrealuser" then
3 
4end
5end)

Now, we need to detect if the player has the tool

01game.Players.PlayerAdded:connect(function(plr)
02if not plr.name == "Thatisnotmyrealuser" then
03local children = plr.Backpack:GetChildren()
04for i = 1, #children do
05    local child = children[i]
06    if child.Name == Tool then
07 
08end
09end
10end)

Now, we need to remove it.

01game.Players.PlayerAdded:connect(function(plr)
02if not plr.name == "Thatisnotmyrealuser" then
03local children = plr.Backpack:GetChildren()
04for i = 1, #children do
05    local child = children[i]
06    if child.Name == Tool then
07plr.Backpack:FindFirstChild("Tool"):Destroy()
08end
09end
10end)
0
I’ll edit it, thanks you so much. raid6n 2196 — 5y

Answer this question