Hi, im currently making a prison life style game, i just want to know how would i give certain players certain tools, like admin only tools?
Hey, you can GetRankInGroup (namecall function under Player) and check if the rank level is higher than x, if so, give weapons.
I dont have a group, i mean like something that checks the players username / user id, then based of that give them a tool
Then you can have a set table in your script like…
local Admins = {--[[userids here]]}
and then check if they’re in the table.
if Admins[Player.UserId] then
--equip tools
end
here is an example script I made that may help you.
-- // Declared Services
local Players = game:GetService("Players");
-- // Private Variables
local Whitelisted = {1, 111, 111} -- Example IDS (Replace or add with your IDs
-- // Functions
local function NewPlayer(player: Player)
if table.find(Whitelisted, player.UserID) then
-- GIVE WEAPON HERE
end
end
Players.PlayerAdded:Connect(NewPlayer)
Would you do like.
[123456789] = true,
No, you can just keep it a simple array.
local Admins = {820590675, 5421770840}
ive made a variable for the tool, how would i tell the script to give the tool to the player, like would you use Tool.Parent = Player.Backpack
or something?
I’ve never done much with tools, but I believe as long as you’re doing it in a server script this should work?
You would do something like this:
local newTool = tool:Clone()
newTool.Parent = Player.Backpack
Oh so a script like this would work?
local Players = game:GetService("Players")
local Tool = game:GetService("ServerStorage")
local Whitelisted = {1, 111, 111}
local function NewPlayer(player)
if table.find(Whitelisted, player.UserId) then
local newTool = Tool:Clone()
newTool.Parent = player.Backpack
end
end
Players.PlayerAdded:Connect(NewPlayer)
Yes if the Whitelisted
array refers to your Admin list, then yes. That should work just fine.
Except ServerStorage
isn’t a tool, i’m sure you meant game:GetService("ServerStorage").Tool
or something.
Yeah i meant local Tool = game:GetService("ServerStorage").Tool
. Thanks.
Also, how would you do multiple tools, would you do multiple clone statements? or is there an easier way
You could have a folder in ServerStorage
called AdminTools
or something.
and then you could do this:
local AdminTools = game:GetService("ServerStorage").AdminTools:GetChildren()
for _, Tool in AdminTools do
if Tool:IsA("Tool") then
local newTool = Tool:Clone()
newTool.Parent = player.Backpack
end
end
and if it isn’t clear that code would run in this block:
And… you would have your tools inside of your AdminTools
folder.
Also, does the script work if a player joins mid game?
Yes. You connect the function to a PlayerAdded
event which fires every time someone joins.
local items = --Insert item location here.--
local item = items:GetChildren()
game.Players.PlayerAdded:Connect(function(plr)
if plr.UserId == game.CreatorId then
item:Clone().Parent = plr.Backpack
end)
This is easy. You can also do it while your in a script add it so if someone buys a game pass they get tools so yeah but basically my script finds if the player is in the table if they are they get a tool. Then if someone owns the game pass they get the tool.