Ad
Log in to vote
0

Welding a red or blue above player's head. No error. How do I fix it?

Asked by 21 days ago

This used to work like 4/5 days ago, but when I came back to it, it doesn't work There's no error or anything Also sometimes it works once in a while

Pictures: https://ibb.co/Fs6kJFJ https://ibb.co/LhFCSph https://ibb.co/FBT1DqJ

There's weld constraint inside B,l,u,e and R,e,d

local red = game.Workspace.RedTeam.OriginalRed
local equipR = game.Workspace.equipRED
local blue = game.Workspace.BlueTeam.OriginalBlue
local equipB = game.Workspace.equipBLUE
local debounce1 = false
local debounce2 = false

local function createRedForPlayer(head,hit)
    local newRed = red:Clone()
    local center = newRed.Center
    newRed.Name = "Red"
    newRed:SetPrimaryPartCFrame(head.CFrame * CFrame.new(0,3,0))
    newRed:SetPrimaryPartCFrame(center.CFrame * CFrame.Angles(0,math.rad(90),0))
    center.Anchored = false
    newRed.Parent = hit.Parent
end

local function createBlueForPlayer(head,hit)
    local newBlue = blue:Clone()
    local center = newBlue.Center
    newBlue.Name = "Blue"
    newBlue:SetPrimaryPartCFrame(head.CFrame * CFrame.new(0,3,0))
    newBlue:SetPrimaryPartCFrame(center.CFrame * CFrame.Angles(0,math.rad(-90),0))
    center.Anchored = false
    newBlue.Parent = hit.Parent
end


equipR.Touched:Connect(function(hit)
    if debounce1 == false then
        debounce1 = true
        if hit.Parent:FindFirstChild("Humanoid") then
            equipR.CanTouch = false
            equipR.Transparency = 0.5
            if hit.Parent:FindFirstChild("Red") then
                print("You're already on this team!")
                wait(2)
                equipR.CanTouch = true
                equipR.Transparency = 0
            else
                if hit.Parent:FindFirstChild("Blue") then
                    hit.Parent:FindFirstChild("Blue"):Destroy()
                end
                local head = hit.Parent.Head
                local weld = Instance.new("WeldConstraint")
                createRedForPlayer(head,hit)
                local thisRed = hit.Parent.Red
                local center = thisRed.Center
                weld.Part0 = head
                weld.Part1 = center
                weld.Parent = head
                print("Welcome to the red team!")
                wait(2)
                equipR.CanTouch = true
                equipR.Transparency = 0
            end
            debounce1 = false
        end
    end
end)

equipB.Touched:Connect(function(hit)
    if debounce2 == false then
        debounce2 = true
        if hit.Parent:FindFirstChild("Humanoid") then
            equipB.CanTouch = false
            equipB.Transparency = 0.5
            if hit.Parent:FindFirstChild("Blue") then
                print("You're already on this team!")
                wait(2)
                equipB.CanTouch = true
                equipB.Transparency = 0
            else
                if hit.Parent:FindFirstChild("Red") then
                    hit.Parent:FindFirstChild("Red"):Destroy()
                end
                local head = hit.Parent.Head
                local weld = Instance.new("WeldConstraint")
                createBlueForPlayer(head,hit)
                local thisBlue = hit.Parent.Blue
                local center = thisBlue.Center
                weld.Part0 = head
                weld.Part1 = center
                weld.Parent = head
                print("Welcome to the blue team!")
                wait(2)
                equipB.CanTouch = true
                equipB.Transparency = 0
            end
            debounce2 = false
        end
    end
end)

Answer this question