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)
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)
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)
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.
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)
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.
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)
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".