Training Center Tool Script

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.

Thanks,
Zac

6 Likes

Hi, can you please indent your code and add code blocks?
Here is an example of one:
image

3 Likes

Oh, your text is cutting off, I can’t see it. How can I indent it?

1 Like

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.

3 Likes

I see you’ve used the ‘’’ instead of the ```. The ` key should be the one below escape.

2 Likes

Cleaning up your code so others can help more easily:

3 Likes

Thank you so much! I haven’t really coded before, so I really appreciate you helping. :slight_smile:

3 Likes

Ohh okay thank you so much, I think I fixed it a bit.

2 Likes

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.

3 Likes

You can use the Players service to get a player’s rank in a group using Players:GetRankInGroup :link:.
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.

4 Likes

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!

3 Likes

Thank you very much! You are very helpful! Would this script go inside the replicated storage, or the Keycard part?

1 Like

Okay thank you very much!! :slight_smile: :slight_smile:

1 Like

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.

1 Like