Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 6 years ago

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

Log in to vote
0
Answered by
LuaDLL 253 Moderation Voter
6 years ago
Edited 6 years ago

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)

0
What If I want to do it with multiple hats? LordSqaureAlistair 3 — 6y
0
It would be the same thing. LuaDLL 253 — 6y
0
And can it be done if your a certain rank in the group? LordSqaureAlistair 3 — 6y
0
Yea i'll edit the script for you LuaDLL 253 — 6y
View all comments (5 more)
0
k edited LuaDLL 253 — 6y
0
Just replace "PUTRANKNUMBERHERE" with the number of the rank when you go into your groups settings LuaDLL 253 — 6y
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 LuaDLL 253 — 6y
0
Do I place the second script inside the model LordSqaureAlistair 3 — 6y
0
Doesn't seem to be working LordSqaureAlistair 3 — 6y
Ad

Answer this question