I have this script which basically puts the hat on your head, I'm wondering if it's possible to make it put it on your head when the player spawns and if your able to do it so it gives it depending on rank?
local hat = script.Parent hat.PrimaryPart = hat:WaitForChild("Head") normal Head. function weldParts(part0, part1) local newWeld = Instance.new("Weld") newWeld.Part0 = part0 newWeld.Part1 = part1 newWeld.C0 = CFrame.new() newWeld.C1 = part1.CFrame:toObjectSpace(part0.CFrame) newWeld.Parent = part0 end hat.Head.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") and not hit.Parent:FindFirstChild("Earl's Coronet")then else return end for _, v in pairs (hit.Parent:GetChildren()) do if v:IsA("Hat") then v:Destroy() end end local head = hit.Parent:FindFirstChild("Head") local newHat = hat:Clone() newHat:FindFirstChild("HatScript"):Destroy() newHat:SetPrimaryPartCFrame(head.CFrame) newHat.PrimaryPart:Destroy() for _, part in pairs (newHat:GetChildren()) do if part:IsA("BasePart") then weldParts(head, part) part.CanCollide = false part.Anchored = false end end newHat.Parent = hit.Parent end)
Um try this?
Create a normal script inside serverscriptserver and put in:
local GroupId = GROUPIDHERE game.Players.PlayerAdded:Connect(function(plr) if plr:IsInGroup(GroupId) then Instance.new("BoolValue",plr).Name = "IsInGroup" local Rank = Instance.new("StringValue") Rank.Name = "GroupRank" Rank.Value = plr:GetRankInGroup(GroupId) Rank.Parent = plr end end)
then edit your code with:
local hat = script.Parent hat.PrimaryPart = hat:WaitForChild("Head") normal Head. function weldParts(part0, part1) local newWeld = Instance.new("Weld") newWeld.Part0 = part0 newWeld.Part1 = part1 newWeld.C0 = CFrame.new() newWeld.C1 = part1.CFrame:toObjectSpace(part0.CFrame) newWeld.Parent = part0 end hat.Head.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") and not hit.Parent:FindFirstChild("Earl's Coronet")then else return end if game.Players[hit.Parent.Name]:FindFirstChild("IsInGroup") and game.Players[hit.Parent.Name]:FindFirstChild("GroupRank").Value >= PUTRANKNUMBERHERE then for _, v in pairs (hit.Parent:GetChildren()) do if v:IsA("Hat") then v:Destroy() end end local head = hit.Parent:FindFirstChild("Head") local newHat = hat:Clone() newHat:FindFirstChild("HatScript"):Destroy() newHat:SetPrimaryPartCFrame(head.CFrame) newHat.PrimaryPart:Destroy() for _, part in pairs (newHat:GetChildren()) do if part:IsA("BasePart") then weldParts(head, part) part.CanCollide = false part.Anchored = false end end newHat.Parent = hit.Parent end end)