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

Moving parts with a dragging tool sometimes causes parts to unsync?

Asked by 4 years ago

Im having an issue while building with a dragging tool I made, for some reason a part might not make joints on the server but will make joints on the client, as a result the client sees a part successfully welding to another part, but on the server the part has fallen and is not welded. here is the drag tool scripts:

Localscript:

--values
local debounce = false
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local tool = script.Parent
local box = Instance.new("SelectionBox")

local selected
local orig  
local dragger
--

function buttondown(mouse)
    local target = mouse.Target
    if target and target:IsA("BasePart") and not target.Locked and
        target:FindFirstChild("PartCore") and target.PartCore:FindFirstChild("Owner") and target.PartCore.Owner.Value == plr.Name then
        if not debounce then
            debounce = true
            selected = target
            dragger = Instance.new("Dragger")
            pcall(function() dragger:MouseDown(selected, Vector3.new(0, 0, 0), {selected}) end)
        box.Adornee = selected
        wait(0.5)-- wait before going again
        debounce = false
        end
    end
end



function buttonup(mouse)
    if dragger then
        local object = mouse.Target
        local sendcfr = selected.CFrame
        script.Parent.MouseUpE:FireServer(object,sendcfr)
        wait()
        orig = nil
        pcall(function() dragger:MouseUp() end)
        box.Adornee = nil
        dragger = nil
    end
end



function mousemove(mouse)
    if dragger then
        pcall(function() dragger:MouseMove(mouse.UnitRay) end)
    end
end




function keymover(key)
    if dragger then
        key = key:lower()
        if key == 'r' then
            dragger:AxisRotate(Enum.Axis.Y)
        elseif key == 't' then
            dragger:AxisRotate(Enum.Axis.Z)
        end
    end
end




function onEquippedLocal(mouse)
    box.Color = BrickColor.new("Lime green")
    box.Parent = plr.PlayerGui

    mouse.Button1Down:connect(function() buttondown(mouse) end)
    mouse.Button1Up:connect(function() buttonup(mouse) end)
    mouse.Move:connect(function() mousemove(mouse) end)
    mouse.KeyDown:connect(keymover)
end






function onUnequippedLocal(mouse)
    if dragger then
        orig = nil
        pcall(function() dragger:MouseUp() end)
        selected = nil
        box.Adornee = nil
        dragger = nil
    end
end


tool.Equipped:connect(onEquippedLocal)
tool.Unequipped:connect(onUnequippedLocal)

serverscript:

function makechanges(plr,object,cframe)


    if object then
        object:BreakJoints()
        object.CFrame = cframe
        object:MakeJoints()
    end
end




script.Parent.MouseUpE.OnServerEvent:Connect(function(plr,object,sendcfr)
    makechanges(plr,object,sendcfr)
end)

sometimes the server/client are synced and other times they de-sync. is there something I can do to keep the server and client updated on the changes the client makes without hitting or missing on the welds?

Answer this question