How do I stop this delay?

So I have this jump pad script that works really well in studio, but in-game it is very delayed, I am pretty sure it is because of lag, but How would I fix it?

This is the script:
I don’t know if it will help

local PlayerTouchingPart = false
local JumpBoostAmount = 50

script.Parent.Touched:Connect(function(hit)
	local Humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
	PlayerTouchingPart = true
	if Humanoid then
		while PlayerTouchingPart == true do
			Humanoid.JumpPower = 150
			Humanoid.Jump = true
			wait(0.2)
			Humanoid.JumpPower = 50
			wait(0.2)
		end
	end
end)

script.Parent.TouchEnded:Connect(function()
	wait(0.5)
	PlayerTouchingPart = false
end)

This is a video showing it(Sorry, I am using roblox’s video recorder):

In Studio:

Average ping - 50
robloxapp-20200818-1502291.wmv (1.2 MB)

In game:

Average ping - 280(I live in South Africa, we have to use European Servers.)
robloxapp-20200818-1505428.wmv (2.4 MB)

Is there a way to stop this delay?

1 Like

For you, maybe not since the ping is so high.

The best way would be to run the script for the jump pads on the client. (On the player.)
That way the jump pads work as aspected, instant feedback without any delay.
You could put a NumberValue inside each pad if they have different levels of JumpPower.

I made this quick script for you to point you in the right direction:

local JumpPadFolderChildren = game.Workspace.JumpPads:GetChildren()

local DefaultJumpingPower

function Jump(character, JumpPower)
    local humanoid = character:FindFirstChild("Humanoid")
    if not humanoid then return end
    humanoid.JumpPower = JumpPower
    humanoid.Jump = true
    wait(0.2)
    humanoid.JumpPower = DefaultJumpingPower
end

local Player = game.Players.LocalPlayer
Player.CharacterAdded:Connect(function(character)
    DefaultJumpingPower = character:WaitForChild("Humanoid").JumpPower
	for i, v in pairs(JumpPadFolderChildren) do
        if v:IsA("BasePart") then
            v.Touched:Connect(function(part)
                if part:IsDescendantOf(character) then
                    local JumpPowerValue = part:FindFirstChild("JumpPowerValue")
                    if not JumpPower then return end
                    Jump(character, JumpPowerValue.Value)
                end
            end)
        end
    end
end)
1 Like

That would help but that isn’t the problem. The ping is not either.

@SpecialEthanRB, how many scripts are running in your game?

How are you concluding ping is not the problem? It obviously is. The only way to circumvent lag introduced by high ping is to run the code on the client, like I did.

280 is not really a ‘high’ ping, it could the be scripts being delayed.

This is an unsupported, unlikely, and ridiculous claim.

If you look at the video @SpacialEthanRB provided, you can see that the lag that occurs matches with the ping OP mentioned. Given that the jumping code is running on the server, it is logical to conclude that a high ping is indeed causing the delay. The fix for this can be found in my previous replies.

280-50 ping is not really considered a ‘high ping’.

1 Like