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
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