Problem with players jump power

I’m making a script that is pretty simple, where when the mutator value changes it will make everyone jump higher… but when it changes it doesn’t change the player’s jump power so Idk what’s wrong with my code…

I’ve tried using a localScript with basically the same code but that still doesn’t work.

the script is not a localScript which might be causing the issue but If possible I’d like it on a regular script

local mutator = script.Parent

mutator.Changed:Connect(function()
	if mutator.Value == true then 
		for i, player in ipairs(game.Players:GetChildren()) do
			Character = player:WaitForChild("Character")
			Humanoid = Character:WaitForChild("Humanoid")

			Humanoid.JumpPower = Humanoid.JumpPower + 15
		end
	else
		for i, player in ipairs(game.Players:GetChildren()) do
			Character = player:WaitForChild("Character")
			Humanoid = Character:WaitForChild("Humanoid")

			Humanoid.JumpPower = Humanoid.JumpPower - 15
		end
	end
end)

any help is super appreciated.
Thanks, Brant

1 Like

The issue is that you’re using WaitForChild() looking for the Character – Character isn’t a child of Player. If you change those lines to player.Character and also I notice Roblox added a property “UseJumpPower” – you’ll need to make sure that is set to true, this code will do what you’re looking for:

local mutator = script.Parent

mutator:GetPropertyChangedSignal('Value'):Connect(function()
	if mutator.Value == true then 
		for i, player in ipairs(game.Players:GetChildren()) do
			Character = player.Character
			Humanoid = Character:WaitForChild("Humanoid")
			Humanoid.UseJumpPower = true
			Humanoid.JumpPower = Humanoid.JumpPower + 15
		end
	else
		for i, player in ipairs(game.Players:GetChildren()) do
			Character = player.Character
			Humanoid = Character:WaitForChild("Humanoid")
			Humanoid.UseJumpPower = true
			Humanoid.JumpPower = Humanoid.JumpPower - 15
		end
	end
end)

oh, I never even knew Roblox added that use jump power… It works so thank you so much :slight_smile:

No worries! :slight_smile: Glad to be able to help! Yeah, not sure when that was added but I learned something new from this. Thanks! :stuck_out_tongue:

1 Like

quick question… would there be any way to “keep” the player’s jump power in this script? What I mean is when the player dies the jump power gets reset back to the default value, but I still want them to jump high even if they die.

Yup – here’s what you’d do for that:

local mutator = script.Parent

mutator:GetPropertyChangedSignal('Value'):Connect(function()
	if mutator.Value == true then 
		for i, player in ipairs(game.Players:GetChildren()) do
			Character = player.Character
			Humanoid = Character:WaitForChild("Humanoid")
			Humanoid.UseJumpPower = true
			Humanoid.JumpPower = Humanoid.JumpPower + 15
		end
	else
		for i, player in ipairs(game.Players:GetChildren()) do
			Character = player.Character
			Humanoid = Character:WaitForChild("Humanoid")
			Humanoid.UseJumpPower = true
			Humanoid.JumpPower = Humanoid.JumpPower - 15
		end
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local Humanoid = char:WaitForChild('Humanoid')
		if mutator.Value then
			Humanoid.UseJumpPower = true
			Humanoid.JumpPower = Humanoid.JumpPower+15
		end
	end)
end)

You also might want to directly set the value of what you want their JumpPower when mutator is on / off instead of adding and subtracting 15.

1 Like

it works! I tried a similar approach with a local script inside the startCharacterScripts and the player.CharacterAdded event thing but it didn’t work so that’s why I was wondering. :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.