Hello, I am quite new to scripting, but I have a cafe group and I wanted to create a training center for it. Basically, I wanted certain ranks to get a Keycard tool when they join the game that will be used to open the door. So far, I have watched a YouTube tutorial, but everybody gets the tool when they join. I don’t know if it is related to this, but here is the script I have for the door so far:
local db = false
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
if db == false then
if hit.Parent:FindFirstChild("Keycard") then
db = true
script.Parent.CanCollide = false
for i = 1, 9 do
script.Parent.Transparency = script.Parent.Transparency + 0.1
wait(0.1)
end
wait(3) -- delay between door opening
for i = 1, 9 do
script.Parent.Transparency = script.Parent.Transparency - 0.1
wait(0.1)
end
db = false
script.Parent.CanCollide = true
end
end
end
end)
I am not sure if I would have to do something in the door or tool script, but I’d really appreciate it if somebody could tell me how to make only certain ranks of my group get the Keycard tool.
Use the tab key to indent, also what I put was an image showing you how to make a code block. Put 3 ``` one line above your code and 3 more on the line below.
You could use that script for checking if the player has a keycard, yes, but you’ll need to make sure that the keycard is only given to the players that are a certain rank in the group or anyone can open the door.
This can be done by:
replicatedStorage = game:GetService("ReplicatedStorage")
keycard = replicatedStorage:WaitForChild("Keycard")
groupId = 1
minRank = 0
game.Players.PlayerAdded:Connect(function(player)
if player:GetRankInGroup(groupId) >= minRank then
wait(2)
local clonedCard = keycard:Clone()
clonedCard.Parent = player:WaitForChild("Backpack")
end
end)
Presuming the Keycard is inside of ReplicatedStorage.
You can use the Players service to get a player’s rank in a group using Players:GetRankInGroup.
You would have to make another script to copy the tool into the player’s backpack though. Probably the main way of doing this is by connecting to a PlayerAdded event and, if the selected player’s rank in the group is above or equal to a certain number, you can clone the keycard tool from server storage into that player’s backpack.
Didn’t know that function existed, what I did in one of my older places was looped through the gs:GetGroupsAsync(), checked if the name was the same, then got the rank which is a pretty bad method. Thanks!
ServerScriptService is a good place to put a lot of Server sided scripts so exploiters can’t steal your hard work. ServerStorage is also a secure place.