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
4 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:

game.Players.PlayerAdded:connect(function(plr)
if plr.name == "Thatisnotmyrealuser" then
    wait()
else
    script.parent:destroy()
end
end)

3 answers

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

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

-- dictionary with names lowercased
local WhiteList = {['azarth'] = true, ['you'] = true}
-- location of tool
local Tool = script:WaitForChild("Tool")

local function PlayerJoined(Player)
    -- if whitelisted
    if WhiteList[Player.Name:lower()] then
    -- clone tool to StarterGear 
        Tool:Clone().Parent = Player:WaitForChild('StarterGear')
    end
end

-- On join
game.Players.PlayerAdded:Connect(PlayerJoined)

-- Players not caught by event
for i,v in pairs ( game.Players:GetPlayers()) do 
    PlayerJoined(v)
end
0
Not exactly what i intended, but it has the same effect in the end, thanks for helping! G0ZZEN 17 — 4y
Ad
Log in to vote
1
Answered by 4 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.

local whitelist = {"YourUser", "FriendsUser"} --add the whitelist users here

script.Parent.Equipped:Connect(function()
    local char = script.Parent
    if char.Name == whitelist then
        print("whitelisted")
    elseif char.Name ~= whitelist then
        script.Parent:Destroy()
    end
end)

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
4 years ago
Edited 4 years ago

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


game.Players.PlayerAdded:connect(function(plr) if not plr.name == "Thatisnotmyrealuser" then end end)

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


game.Players.PlayerAdded:connect(function(plr) if not plr.name == "Thatisnotmyrealuser" then local children = plr.Backpack:GetChildren() for i = 1, #children do local child = children[i] if child.Name == Tool then end end end)

Now, we need to remove it.


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

Answer this question