How too get a humanoids jumppower

I’m trying to get a humanoids jump power for when they hit a part.

Here’s my code so far that’s giving me an error "JumpPower is not a valid member of MeshPart “Workspace.naderbocker2.LeftUpperArm”

local block = script.Parent
db = false

block.Touched:Connect(function(hit)
	if db == false then
		db = true
		hit.JumpPower = 0
		wait(1)
		hit.JumpPower = 50
		db = false
end)

Thanks.

You’re making hit’s JumpPower to 50, however, hit is essentially what the part hit.
To get the humanoid you need to do

hit.Parent:FindFirstChild("Humanoid")

also make the humanoid’s property “UseJumpPower” to true

It gives me an error " Workspace.Part.Disapear:8: attempt to index nil with ‘JumpPower’"

Here is my code -

local block = script.Parent
db = false

block.Touched:Connect(function(hit)
	if db == false then
		db = true
		hit.Parent:FindFirstChild("Humanoid").JumpPower = 0
		wait(1)
		hit.Parent:FindFirstChild("Humanoid").JumpPower = 50
		db = false
end)

You need to check if the part is a player first

local block = script.Parent
db = false

block.Touched:Connect(function(hit)
	if db == false and hit.Parent.FindFirstChild("Humanoid") then
       local hum = hit.Parent:FindFirstChild("Humanoid")
		db = true
		hum.JumpPower = 0
		task.wait(1)
		hum.JumpPower = 50
		db = false
end)
1 Like

Thanks, but it did not work. It also gave me an error which I fixed but after that it still did not work.

So you are trying to make it so the player’s jumppower increases when they step on a part, correct?

No, I want too make it decrease. So when they step on a part they cant jump anymore.

Try this code:

local block = script.Parent
db = false

block.Touched:Connect(function(hit)
	if db == false then
		db = true
		hit.Parent:FindFirstChild("Humanoid").JumpPower = 0
		wait(1)
		hit.Parent:FindFirstChild("Humanoid").JumpPower = 50
		db = false
       end
end)

You may have forgot an end after the if statement.

Edit: Some better explaining

JumpPower is a property of a Humanoid class object.

Currently, you’re trying to change the property of a BasePart class object, and that property doesn’t exist.

Instead, you need to be looking for the humanoid associated with the model and changing the properties belonging to that.


local function change_jump_power(partTouched)

    -- If the part touched, its parent or a humanoid belonging to its parent doesn't exist...
    if not partTouched or not partTouched.Parent or not partTouched.Parent:FindFirstChildOfClass("Humanoid") then return end
    
    -- Reduce the existing jumppower by 10
    partTouched.Parent:FindFirstChildOfClass("Humanoid").JumpPower -= 10
end

-- Connect when the part is touched
part.Touched:Connect(change_jump_power)

Hope this helps.

This doesn’t seem to be working either. It also doesn’t give me any errors.

I am not sure if this has anything to do with it, however I looked at the Humanoid properties and saw you need to enable UseJumpPower.

image

So, you should try use JumpHeight instead:

local block = script.Parent
db = false

block.Touched:Connect(function(hit)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	local Character = Player.Character
	if db == false then
		db = true
		Character.Humanoid.JumpHeight = 0
		task.wait(1)
		Character.Humanoid.JumpHeight = 7.2
		db = false
	end
end)
1 Like

You can also enable JumpPower if you wanted to. This is a post I found: UseJumpPower

1 Like

Thanks, it does work. One more thing though, it does work well but it gives me an error " Workspace.Part.Disapear:6: attempt to index nil with 'Character".

Do you know why?

I do get this error sometimes, but I’m not sure why. It hasn’t had an effect on my game so you should be all good.

1 Like

i did say to set “UseJumpPower” to true

1 Like

it means usually means the character hasnt loaded

its trying to use character which is nil

1 Like