So I am a Scripter/Owner for a Napoleonic group and I am trying to make it so that when a player spawns in they spawn with a hat but if the player is for example rank 234 in my group and another player is rank 100 they would spawn with a different hat, this is the script I tried but it doesn’t work so if someone would help me point out the problem I would appreciate it.
local pModel = script.Parent
local hum = pModel:WaitForChild("Humanoid")
local hat = game.ServerStorage.Accessories.NerdHair:Clone()
local hat2 = game.ServerStorage.Accessories.FrenchHat1:Clone()
local Group = 5452911
game.Players.PlayerAdded:Connect(function(player)
local character = nil
if player:GetRankInGroup(Group) == 254 then
hum:AddAccessory(hat)
hum:AddAccessory(hat2)
else
if player:GetRankInGroup(Group) == 253 then
hum:AddAccessory(hat)
end
end
end)
Why do you have pModel and hum defined outside the PlayerAdded event? That’s most likely your issue.
When the player joins, PlayerAdded is triggered, giving you the Player object which you can get the Character and Humanoid from.
local hat = game.ServerStorage.Accessories.NerdHair:Clone()
local hat2 = game.ServerStorage.Accessories.FrenchHat1:Clone()
local Group = 5452911
game.Players.PlayerAdded:Connect(function(player)
local character = player.Character
local hum = character.Humanoid
if player:GetRankInGroup(Group) == 254 then
hum:AddAccessory(hat)
hum:AddAccessory(hat2)
elseif player:GetRankInGroup(Group) == 253 then
hum:AddAccessory(hat)
end
end)
Please edit your post, highlight your code, then click on the button above your edit window with the </> icon to format that text so we can read it a little easier.
What type of script is this, LocalScript or Script?
Where is the script located?
To change the type of hat for different ranks you can’t use == since that only gets that rank. Use <= or >= or a combination of them so you can have more than two ranges of ranks and hats.
Okay, I think I see the issue. Since you’re using StarterCharacterScripts, the script might be running before the ServerStorage has loaded. You should try to utilize a WaitForChild() on the variables for the hats.
local players = game:GetService("Players")
local hat = game.ServerStorage.Accessories.NerdHair:Clone()
local hat2 = game.ServerStorage.Accessories.FrenchHat1:Clone()
local Group = 5452911
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local hum = character:WaitForChild("Humanoid")
if player:GetRankInGroup(Group) == 254 then
hum:AddAccessory(hat)
hum:AddAccessory(hat2)
elseif player:GetRankInGroup(Group) == 253 then
hum:AddAccessory(hat)
end
end)
end)
Needs to be a server script since you’re referencing “ServerStorage” which can only be accessed from server scripts.
local players = game:GetService("Players")
local hat = game.ServerStorage.Accessories.NerdHair
local hat2 = game.ServerStorage.Accessories.FrenchHat1
local Group = 5452911
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local hum = character:WaitForChild("Humanoid")
if player:GetRankInGroup(Group) == 254 then
local hatClone = hat:Clone()
hum:AddAccessory(hatClone)
local hat2Clone = hat2:Clone()
hum:AddAccessory(hat2Clone)
elseif player:GetRankInGroup(Group) == 253 then
local hat2Clone = hat2:Clone()
hum:AddAccessory(hat2Clone)
end
end)
end)
Ahh I found the problem, it was another script I made that would remove any accessories the player had on them when they removed, it most’ve removed them after the hats where given