Hi, i created this simple trmpoline for jumping purposes! The only flaw it’s that sometimes it can be laggy.
Can you review my code?
local JP = 10
script.Parent.Touched:Connect(function(hit)
local human = hit.Parent:FindFirstChild("Humanoid")
if human then
human.JumpPower = JP
human.Jump = true
wait(0.1)
human.JumpPower = 50
end
end)
What do you mean by laggy? Is it not always bouncing up to its height that it’s supposed to? I’m guessing that because I used to have a problem like that.
local JP = 10
local db = false
script.Parent.Touched:Connect(function(hit)
local human = hit.Parent:FindFirstChild("Humanoid")
if human and db == false then
db = true
human.JumpPower = JP
human.Jump = true
wait(0.1)
human.JumpPower = 50
wait(1)
db = false
end
end)
A debounce is needed because the touched event fires more than once. Using one means we ignore all other touched events besides the first one.
Also, if you’re going to post code on here, please properly indent it.
Part of the “lag” problem has to do with the fact that the Touched event is bad at responding to Humanoids. When you land on a part, the Touched event will not fire until the character finishes “landing” and settles after a moment. The FloorMaterial property of the Humanoid does update instantly, though, so you can work around the broken Touched behavior with an ugly hack by listening for the FloorMaterial to change from Air. The only other problem here is that a JumpPower of 10 isn’t high enough for the FloorMaterial to change, so really it’s going to require a precise calculation to determine when the character should land given how high they last jumped, and a raycast to check if the character is landing on the trampoline part.
This would be much easier if the Touched event just responded properly to jumping humanoids.
an additional workaround would be to place an invisible, non-colliding “hitbox” part above the trampoline, so then the legs will make contact with it immediately and fire the Touched event instead of the humanoid stopping and hovering over it for a bit.
I would guess you’re still seeing it jump like this
instead of like this
because of the time it takes the jump animation to let the foot touch the part after the humanoid lands. I assumed that was the “lag” you were talking about.
I’d like to add you’d probably be better off putting this in a local script otherwise the debounce will take place for everyone. Or you could make a table of players and have a debounce value inside it
It’s not the property that replicates, it’s the physics. The same goes for WalkSpeed. The actual property doesn’t replicate, the changes in physics this creates does.