Delay in touched event due to lag

I have a jump pad that when they touch it, it fires an event to make the player jump. The issue is that when the player has high ping, they take a while to jump (they sit there for a second before it makes them jump). Here is the code

 pad = script.Parent

function jump(Hit)
    local humanoid = Hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
    local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
    game.ReplicatedStorage.Jump:FireClient(player)
    print("fired")
end
end
pad.Touched:Connect(jump)
5 Likes

The code might be laggy because of other code in the background, to prevent this. Delete lines that aren’t used in codes. Like this example

local me = game.ReplicatedStorage.Me -- Delete
local jamal = me.Parent.Jamal

local Jamalclone = jamal:Clone()
1 Like

The game is based around the jump pads, there are like hundreds of them…
So your saying intead of using

local pad = script.parent 
 pad.cancolide = false

Just use

script.parent.cancollide = false

?

4 Likes

use collection service or use for loops using 1 script not multiple

6 Likes

if your script is really long be careful making random variables. else it doesn’t matter as roblox already cleans your scripts every 30 seconds

7 Likes

Perhaps try changing the script from a server script to a local script. It already looks like your using some code to make the user jump so try moving that code over to this script and have it all done on this script.

6 Likes

As far as I know, there is no need to connect an event.
The only code you need to make somebody jump is

Humanoid.Jump = true

pad = script.Parent

function jump(Hit)
    local humanoid = Hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
    local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
    humanoid.Jump = true
    print("fired")
end
end
pad.Touched:Connect(jump)
4 Likes

Local script doesnt work, somebody told me that running an event would make it smoother awhile back, I dont know if that is true though

2 Likes

The issue is with players with high ping this wouldn’t fix anything. Also its possible they have some sort of custom high jump as they said its a “jump pad”.

6 Likes

What the person said about the event was correct but they were referring to a context where it was server → client. In this case we are only talking about the client so a RemoteEvent will not work which is why you need to move the code from your client event and move it to this script for it to work.

4 Likes

I combined the scripts like you guys said and it is still just as delayed. For some more context, It works fine for people with normal ping, but for people with bad ping or recording the game (what I’m testing) it gets really delayed.

2 Likes

Did you switch the run context to client? Also when you say ping do you also mean low fps?

3 Likes

I changed the script to this

pad = script.Parent

function jump(Hit)
    local humanoid = Hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
    local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
    humanoid.Jump = true
    print("fired")
end
end
pad.Touched:Connect(jump)
2 Likes

can I see your local script

(30char)

2 Likes
game.ReplicatedStorage.Jump.OnClientEvent:Connect(function()
    local plr = game.Players.LocalPlayer 
    plr.Character.Humanoid.Jump = true
end)
1 Like

I’m assuming you connect this to client to make it run smoother as player needs network ownership over character?

this script has no use

3 Likes

You didn’t answer my question? Have you tried switching the RunContext for your main jump pad script from Legacy to Client? Alternatively you could grab the code and put it in a local script.

Example:
image

2 Likes
 pad = script.Parent

function jump(Hit)
    local humanoid = Hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
    local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
    game.ReplicatedStorage.Jump:FireClient(player)
    print("fired")
end
end
pad.Touched:Connect(jump)

This was my script before I changed it to what you suggested

2 Likes

I just tried it out, It still didn’t work

2 Likes

pad = script.Parent

it should be local pad = script.Parent

2 Likes