Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is it possible to make unions/parts/meshes weld onto your head if in a group?

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)

1 answer

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)

9 comments

0

What If I want to do it with multiple hats?

0

It would be the same thing.

0

And can it be done if your a certain rank in the group?

0

Yea i'll edit the script for you

0

k edited

0

Just replace "PUTRANKNUMBERHERE" with the number of the rank when you go into your groups settings

0

If you dont know what i mean by the group rank number then go to your group and click group admin and click rolls and it would be under Rank(0-255) and that is the number

0

Do I place the second script inside the model

0

Doesn't seem to be working

This discussion is preserved as it was. New answers, comments, and votes are closed.