Intro
During my time searching on Roblox - including the developer forum, I’ve noticed not many tutorials on roblox military tutorials, including group/team based hat/clothes giving etc. So, as I’m becoming quite an experienced Roblox military developer I’ve decided to help people that need it.
Group Based Hat Giver on Spawn
One of the many things I searched for when beginning Roblox military development was a way to give certain ranks/divisions a hat depending on their rank and division. I found nothing that could help me so I used trial and error to try and fix it. Here’s some code that you will need:
local GroupID = 11017426
local GroupRank = 17
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(char)
if plr:GetRankInGroup(GroupID)>= GroupRank and char and char:findFirstChild("Cap") == nil then
local g = game.ReplicatedStorage.Beret:Clone()
g.Parent = char
local C = g:GetChildren()
for i=1, #C do
if C[i].className == "Part" or C[i].className == "UnionOperation" or C[i].className == "MeshPart" then
local W = Instance.new("Weld")
W.Part0 = g.Middle
W.Part1 = C[i]
local CJ = CFrame.new(g.Middle.Position)
local C0 = g.Middle.CFrame:inverse()*CJ
local C1 = C[i].CFrame:inverse()*CJ
W.C0 = C0
W.C1 = C1
W.Parent = g.Middle
end
local Y = Instance.new("Weld")
Y.Part0 = char.Head
Y.Part1 = g.Middle
Y.C0 = CFrame.new(0, 0, 0)
Y.Parent = Y.Part0
end
local h = g:GetChildren()
for i = 1, # h do
if h[i].className == "Part" or h[i].className == "UnionOperation" or C[i].className == "MeshPart" then
h[i].Anchored = false
h[i].CanCollide = false
end
end
end
end)
end)
You don’t have to use groupID and groupRank variables but I did it for this tutorial for simplicity. This is what your explorer should look like:
Group Rank Hat Giver on Touch
This is the code you will need:
local Beret = script.Parent.Parent.Beret
function Beret(hit)
if hit.Parent:findFirstChild("Humanoid") ~= nil and hit.Parent:findFirstChild("AAC") == nil and hit.Parent:findFirstChild("BA") == nil and hit.Parent:findFirstChild("ETS-COL") == nil and hit.Parent:findFirstChild("ETS-OR") == nil and hit.Parent:findFirstChild("ETS-OF") == nil and hit.Parent:findFirstChild("OTC") == nil and hit.Parent:findFirstChild("PARAS") == nil and hit.Parent:findFirstChild("RMP-COL") == nil and hit.Parent:findFirstChild("RMP-OF") == nil and hit.Parent:findFirstChild("RMP-OR") == nil and hit.Parent:findFirstChild("Staff") == nil then
local g = Beret:Clone()
g.Parent = hit.Parent
local C = g:GetChildren()
for i=1, #C do
if C[i].className == "Part" or C[i].className == "UnionOperation" or C[i].className == "MeshPart" then
local W = Instance.new("Weld")
W.Part0 = g.Middle
W.Part1 = C[i]
local CJ = CFrame.new(g.Middle.Position)
local C0 = g.Middle.CFrame:inverse()*CJ
local C1 = C[i].CFrame:inverse()*CJ
W.C0 = C0
W.C1 = C1
W.Parent = g.Middle
end
local Y = Instance.new("Weld")
Y.Part0 = hit.Parent.Head
Y.Part1 = g.Middle
Y.C0 = CFrame.new(0, 0, 0)
Y.Parent = Y.Part0
end
local h = g:GetChildren()
for i = 1, # h do
if h[i].className == "Part" or h[i].className == "UnionOperation" or C[i].className == "MeshPart" then
h[i].Anchored = false
h[i].CanCollide = false
end
end
end
end
TouchPart.Touched:Connect(function(touched)
if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
local Player = Players:GetPlayerFromCharacter(touched.Parent)
if Player:IsInGroup(000000) then
script.Parent.Touched:connect(Beret)
end
end
end)
With this script, you will need to change the Player:IsInGroup() to your group ID, and you can have as many functions as you wish. This is what your explorer should look like: