Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Touched Event sometimes not activating for Jump Pad?

Asked by 3 months ago

Hi! I hope you have a nice day. I have a problem with the Touched Event where when the player touches the jump pad, it sometimes won't activate immediately. Also when I press the Space bar, it doesn't boost the jump (the Jump Power is supposed to be 183). The Part is CanCollide off because it works better than when it is on.

Code:

script.Parent.Touched:Connect(function(hit) local h = hit.Parent:FindFirstChild("Humanoid")

if h ~= nil then wait() h.JumpPower = 184

    wait(0.5)

    h.JumpPower = 93

end end)

What I've tried:

Using various methods of the same code but in different layout Watching Youtube tutorials Reduce graphics quality so lag is reduced

Thanks

0
to use hit, you need to turn on cancollide, I sugges you turn that on in the script, also what does h refer to if i get that info i can prob answer ayuu_ondev 58 — 3mo
0
also if you have diff scripts in the trampoline can you please share them ayuu_ondev 58 — 3mo

1 answer

Log in to vote
1
Answered by
uhi_o 417 Moderation Voter
3 months ago

Your code is pretty mess there. I have realized that you have forgot a '.' after the h when getting the property JumpPower from the Humanoid.

Let me write up a neatter code

script.Parent.Touched:Connect(function(hit) 
    local hum = hit.Parent:FindFirstChild("Humanoid")
    if hum then --If it has been found
        hum.JumpPower = 184
        wait(0.5)
        hum.JumpPower = 93
    end
end)

Now that's your code. But I see an issue with it. Every time the user steps on the part they get 184 JumpPower. To prevent that, we would need a debounce.

I'll try to make this as clear as possible since I have hard time explaining debounce

local TouchedPart = false --Our debounce variable

script.Parent.Touched:Connect(function(hit) 
    local hum = hit.Parent:FindFirstChild("Humanoid")
    if hum then --If it has been found
        if TouchedPart == false then --Making sure it has not touched the part before
            TouchedPart = true --So it does not fire another time
            hum.JumpPower = 184
            wait(0.5)
            hum.JumpPower = 93
            TouchedPart = false --"Reconnecting" the event so it runs again
    end
end)

It's basically a holder variable which is used to prevent an event to fire multiple times.

You can always read this article if I did not explain well. https://developer.roblox.com/en-us/articles/Debounce

Remember to accept this answer if it has helped solve your issue

0
+1 raid6n 2309 — 3mo
1
Thanks it works but I think the not jumping issue is sometimes due to roblox not registering it. I appreciate it MelodicSea5914 21 — 3mo
Ad

Answer this question