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

Why is this part position not updating (help with welds and tools)?

Asked by 5 years ago

I am trying to make a placement script with tools and welds, this script is located inside of a part calling "Placing Mat"

local Placed = false
local eq = false
local eqtool
local Handi
local RaiseV

script.Parent.EPressed.OnServerEvent:Connect(function(player)
    for i,v in pairs (player.Character:GetChildren()) do
        if v:IsA("Tool") and (player.Character.HumanoidRootPart.Position - script.Parent.Position).magnitude < 5 and Placed == false then
            Handi = v.Handle
            RaiseV = v.Value
            eqtool = v
            Handi.Parent = script.Parent
            Handi.CFrame = CFrame.new(Vector3.new(script.Parent.Position.X, script.Parent.Position.Y + RaiseV.Value, script.Parent.Position.Z))
            Handi.Orientation = Vector3.new(v.RotValue.Value.X, v.RotValue.Value.Y, v.RotValue.Value.Z)
            Handi.Anchored = true
            for c,d in pairs (Handi:GetDescendants()) do
                if d:IsA('BasePart') then
                    d.Anchored = true
                end
            end
            Placed = true
            v.Parent = script.Parent
        elseif Placed == true and (player.Character.HumanoidRootPart.Position - script.Parent.Position).magnitude < 5 then
            for f,g in pairs (Handi:GetDescendants()) do
                if g:IsA('BasePart') then
                    g.Anchored = false
                end
            end
            Handi.Anchored = false
            Handi.Parent = eqtool
            eqtool.Parent = player.Backpack
            Placed = false
        end
    end
end)

I have another script inside the tool handle that updates the parts position when a tool is activated nearby

script.Parent.Parent:FindFirstChild("IngAdded").OnServerEvent:Connect(function(player)
    for i,v in pairs (player.Character:GetChildren()) do
        if v:IsA("Tool") and v.Name ~= "EG" and script.Parent.Parent.Name ~= 'MC' then
            local igo = script.Parent.Unionme
            v.Activated:Connect(function()
                if v.Name ~= "MC" and script.Parent.Parent.Name ~= 'Tool' and (player.character.HumanoidRootPart.Position - script.Parent.Position).magnitude < 5 then
                    script.Parent.Unionme.Position = Vector3.new(script.Parent.Unionme.Position.X,script.Parent.Unionme.Position.Y+2, script.Parent.Unionme.Position.Z)
                end
            end)
        end
    end
end)

The part moves but then it reverts back to its original position once it gets put back into the tool

This is what it looks like. I want the parts position to stay the way it is but it wont. Why and how do I fix this? https://gyazo.com/4f4a4d26aa3d2805a7d8f9c338ed45f3

Answer this question