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

How to offset to compensate delay from remote events?

Asked by
TtuNkK 37
3 years ago

I'm trying to make a forcefield surrounding the player after getting input. I'm doing this by having a local script fire to a server script with a remote event, but the issue is that it has a delay, which would make me teleport back a few steps.

Does anyone know a good solution to offset the delay?

Local Script

UIS.InputBegan:Connect(function(input, isTyping)
    if isTyping then
        return
    elseif input.KeyCode == Enum.KeyCode.F then
        if debounce == false and isBroken.Value == false then
            if isActive == false then
                ended = false
                isActive = true
                Block:FireServer(isActive)
            end
        end
    end
end)

Server Script

Block.OnServerEvent:Connect(function(player, isActive)
    local blockfield = Meshes:WaitForChild("BlockField"):Clone()
    blockfield.CFrame = hrp.CFrame
    blockfield.Parent = Character
    local weld = Instance.new("ManualWeld")
    weld.Part0 = blockfield
    weld.Part1 = hrp
    weld.C0 = weld.Part0.CFrame:toObjectSpace(weld.Part1.CFrame)
    weld.Parent = weld.Part0
end)

Answer this question