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:
1 | game.Players.PlayerAdded:connect( function (plr) |
2 | if plr.name = = "Thatisnotmyrealuser" then |
3 | wait() |
4 | else |
5 | script.parent:destroy() |
6 | end |
7 | end ) |
You can just clone it to their StarterGear if they are whitelisted.
01 | -- dictionary with names lowercased |
02 | local WhiteList = { [ 'azarth' ] = true , [ 'you' ] = true } |
03 | -- location of tool |
04 | local Tool = script:WaitForChild( "Tool" ) |
05 |
06 | local 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 |
12 | end |
13 |
14 | -- On join |
15 | game.Players.PlayerAdded:Connect(PlayerJoined) |
16 |
17 | -- Players not caught by event |
18 | for i,v in pairs ( game.Players:GetPlayers()) do |
19 | PlayerJoined(v) |
20 | end |
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.
01 | local whitelist = { "YourUser" , "FriendsUser" } --add the whitelist users here |
02 |
03 | script.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 |
10 | end ) |
just place this in a serverscript inside of your tool. hope this helped you :)
First, we need to see if the player is not “Theisnotmyrealuser”
1 | game.Players.PlayerAdded:connect( function (plr) |
2 | if not plr.name = = "Thatisnotmyrealuser" then |
3 |
4 | end |
5 | end ) |
Now, we need to detect if the player has the tool
01 | game.Players.PlayerAdded:connect( function (plr) |
02 | if not plr.name = = "Thatisnotmyrealuser" then |
03 | local children = plr.Backpack:GetChildren() |
04 | for i = 1 , #children do |
05 | local child = children [ i ] |
06 | if child.Name = = Tool then |
07 |
08 | end |
09 | end |
10 | end ) |
Now, we need to remove it.
01 | game.Players.PlayerAdded:connect( function (plr) |
02 | if not plr.name = = "Thatisnotmyrealuser" then |
03 | local children = plr.Backpack:GetChildren() |
04 | for i = 1 , #children do |
05 | local child = children [ i ] |
06 | if child.Name = = Tool then |
07 | plr.Backpack:FindFirstChild( "Tool" ):Destroy() |
08 | end |
09 | end |
10 | end ) |