Error to find Player's Backpack:

Heya, there!

I currently made a script to work once touching the tool called ballon, go to the backpack of your character, and change the value of the JumpPower/JumpHeight!

However, as testing inside of Roblox Studio, in the Output, it tells me that cannot find it. Moreover, it tells me that it is not a valid member of my character’s body parts:

ballon = workspace.Red_Ballon.Handle

FindHumanoid = game:FindFirstChild("Humanoid")

ballon.Touched:Connect(function(player)
	if FindHumanoid then
		print(player.Name .. " touched me")
	end
	ballon.Parent = player.Backpack
	
	if FindHumanoid.JumpHeigh or FindHumanoid.JumpPower == 50 then
		FindHumanoid.JumpHeight = 85
	elseif FindHumanoid.JumpPower then
		FindHumanoid.Jumpower = 85
	else
		print("Something is wrong with the script!!")
	end
end)

If it is possible for anyone to assist me with this problem, that would be appreciatable!

Thank you!

1 Like

I think you may have misspelled JumpHeight.

2 Likes

I think it’s a bit better to use WaitForChild() Function.

Since you are “trying” to find the Humanoid. It’s a completely useful function for that.

--[Example]

local Part = workspace:WaitForChild('MyPart')

if Part ~= nil then
       -- [ My Part exists!
end

After it waits for it to exist, It will continue.

And about the part of the script if h.JumpHeight or h.JumpPower == 50 then I suggest you use or h.JumpPower >= 50 or h.JumpPower == 50 It’s more useful.

Also, You can use this to help you even more.

if hit.Parent:FindFirstChild('Humanoid') then
       -- [ script... 
end

I use that a lot to make killing bricks, and other stuff.

1 Like

Okay, so I tried following your guide for a short, and I reduced+changed a few things:

ballon = workspace.Red_Ballon.Handle

RBLX_PLAYER_HUMANOID = game:WaitForChild("Humanoid")

ballon.Touched:Connect(function(player)
	if RBLX_PLAYER_HUMANOID then
		print(player.Name .. " touched me")
	end
		
	ballon.Parent = player.Backpack
	
	if RBLX_PLAYER_HUMANOID.JumpHeight >= 50 or RBLX_PLAYER_HUMANOID.JumpPower == 50 then
		RBLX_PLAYER_HUMANOID.JumpHeight = 100
		RBLX_PLAYER_HUMANOID.JumpPower = 100
	end
end)

Once tested out, it does not appear any issues with the Output! Although, it does not change the Humanoid’s JumpHeight and JumpPower

Sorry its completely messed up right now.

Try changing up to this and reply if did any effects!

ballon = workspace.Red_Ballon.Handle

local db = false -- [ Using this so It wont give a complex thing that I cant explain a lot, but it just prevents spamming.
ballon.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') and db == false then
            db = true
            local Char = hit.Parent
           RBLX_PLAYER_HUMANOID = char:WaitForChild("Humanoid")
            
            if RBLX_PLAYER_HUMANOID then 
                  if RBLX_PLAYER_HUMANOID.JumpHeight >= 50 or RBLX_PLAYER_HUMANOID == 50 or RBLX_PLAYER_HUMANOID.JumpPower == 50 or RBLX_PLAYER_HUMANOID.JumpPower >= 50 then 
                      RBLX_PLAYER.HUMANOID.JumpHeight = 100
                      RBLX_PLAYER_HUMANOID.JumpPower = 100
                  end
            end
   end
end)
1 Like

image

I quickly inserted the code and no errors were founded. Even so, JumpHeigh did not change once finding my Humanoid.

Moreover, it gives me a warning (not an error) on the Output stating that can be possible to find in-game infinite yield:

image

The game does not have an humanoid

I’m a bit confused as to why you need to make a touched event for this, when you step on a tool’s handle it automatically parents it to your character, wouldn’t it be better in your case to give the JumpPower and JumpHeight on equip and revert them on unequip?

That is what I have been trying to do actually!

But, to make sure, I want to make the touched event print that the specific player got the Handle part. Once printed, the tool’s parent is going to be the player’s backpack (i.e the inventory), and furthermore, change the JumpPower & JumpHeight localizing the Humanoid!

As putting all together (as you can see in the first script at the topic’s description, it tells me something unexpected… It turns out that the Backpack is not a valid member of different body parts of my R15 character…

That’s because what touches the handle is not the player, usually people do hit.Parent to get the Character of the player since the parent of a limb is the Character, then they use Players:GetPlayerFromCharacter() to get the player, passing the Character they found (hit.Parent) into the brackets and then using an if statement to check if the parent is a valid player

Example of a typical player hit detection

part.Touched:Connect(function(hit)
    local character = hit.Parent
    
    local player = Players:GetPlayerFromCharacter(character)
    
    if not player then
        return
    end
    
    -- Code here executes if what touched the part is a player
end)
1 Like

Well, in this case, I inserted the hit.Parent as well as Players:GetPlayerFromCharacter + more notes which are the print line, parent of the variable ballon, and in case it finds the character’s humanoid, changes the JumpPower and JumpHeight:

local Players = game:GetService("Players")

ballon = workspace.Red_Ballon.Handle

ballon.Touched:Connect(function(hit)
	local character = script.Parent
	local player = Players:GetPlayerFromCharacter(character)
	if not player then
		return
	end
	print(player.Name, player.DisplayName .. "touched the part!")
	ballon.Parent = player.Backpack
	local human = game:FindFirstChild("Humanoid")
	if human then
		human.JumpPower = 85
		human.JumpHeight = 85
	end
end)

Testing it out once again on Roblox Studio, no issues or warnings were found in the Output, yet no alterations were made in the Script for some reason… XP

Why are you doing game:FindFirstChild("Humanoid")? You have to find the humanoid in the character, so change that to character:FindFirstChildOfClass("Humanoid")

1 Like

Oh, whoops, silly me! I thought it would find like a normal part on the Workspace

I fixed it now in the local variable human (representing Humanoid), and played on! Checking out my character’s Humanoid > Jump Settings > JumpHeight, unfortunately, it prints only 7.2 as the value…

However, I did not stop here! I tried adding another information, WalkSpeed, and it appears that both of them do not do any modifications whatsoever

local Players = game:GetService("Players")

ballon = workspace.Red_Ballon.Handle

ballon.Touched:Connect(function(hit)
	local character = script.Parent
	local player = Players:GetPlayerFromCharacter(character)
	if not player then
		return
	end
	print(player.Name, player.DisplayName .. "touched the part!")
	ballon.Parent = player.Backpack
	local human = character:FindFirstChildOfClass("Humanoid")
	if human then
		human.UseJumpPower = true
		human.JumpPower = 85
		human.JumpHeight = 85
		human.WalkSpeed = 100
	end
end)

Okay I see another issue, you try to get the character using script.Parent, change that to hit.Parent

1 Like

Okay! So, I eventually changed this right now, and now, playing in the Baseplate, and touching, the tool disappears and makes my character not possible to move, only jump with the different values being distributed on the Script

I am not sure why it is not letting me do any actions except for jumping… Quite odd

I’m not sure if the Tool disappearing is what you wanted, the reason it disappears is because you parent the handle ot backpack, you have to parent the tool, so ballon.Parent.Parent

And as for the character break, that’s odd, I tried it out how I think you set it up and it works for me, I get a lot of jump height and walkspeed, maybe something is interfering with the code?

1 Like

From touchinterests you dont get what player touched it you get what part touched it
so

ballon = workspace.Red_Ballon.Handle

FindHumanoid = game:FindFirstChild("Humanoid") -- Dont know what this is exacly for (seems like trying to find humanoid but failed)

ballon.Touched:Connect(function(hit)
	local Character = nil
	if hit.Parent:IsA("Model") and game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) then
		Character = hit.Parent
	elseif hit.Parent.Parent:IsA("Model") and game:GetService("Players"):GetPlayerFromCharacter(hit.Parent.Parent) ~= nil then -- Double check
		Character = hit.Parent.Parent
	else
		return error("The touch was not from a player. | " .. ballon:GetFullName())
	end
	local Player = game:GetService("Players"):GetPlayerFromCharacter(Character)
	local Humanoid = Character:FindFirstChildOfClass("Humanoid")
	if Humanoid then
		print(Player.Name .. " touched me")
	end
	ballon.Parent = Player.Backpack

	if Humanoid.JumpHeigh or Humanoid.JumpPower == 50 then
		Humanoid.JumpHeight = 85
	elseif Humanoid.JumpPower then
		Humanoid.Jumpower = 85
	else
		return error("Something is wrong with the script!")
	end
end)

Keeping it simple and normal
i always suggest using

local Character = nil
if hit.Parent:IsA("Model") and game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) then
	Character = hit.Parent
elseif hit.Parent.Parent:IsA("Model") and game:GetService("Players"):GetPlayerFromCharacter(hit.Parent.Parent) ~= nil then -- Double check
	Character = hit.Parent.Parent
else
	return error("The touch was not from a player.")
end
local Player = game:GetService("Players"):GetPlayerFromCharacter(Character)
local Humanoid = Character:FindFirstChildOfClass("Humanoid")

After a touch script (only if you willing to use it for a character)

Ah, sorry! I did not see that I settled up the WalkSpeed to a value that could make my character “frozen”!

Corrected the little parts and added another two pieces of information, which are getting the tool with a “tada” sound and playing a little bounce noise in the statement if Humanoid.Jumping then

ballon = workspace.Red_Ballon.Handle

ballon.Touched:Connect(function(hit)
	local character = hit.Parent
	local player = Players:GetPlayerFromCharacter(character)
	if not player then
		return
	end
	print(player.Name, player.DisplayName .. " touched the Handle!")
	ballon.Parent.Parent = player.Backpack
	local human = character:FindFirstChildOfClass("Humanoid")
	if human then
		human.UseJumpPower = true
		human.JumpPower = 85
		human.JumpHeight = 85
		human.WalkSpeed = 16
	end
	ballon["tada.wav/victory.wav HD"]:Play()
	
	wait(5)
	
	if human.Jumping then
		ballon["bounce boing sound effect"]:Play()
	end
	
	if ballon.Parent.Parent == nil then
		ballon["bounce boing sound effect"].Playing = false
        human.UseJumpPower = true
		human.JumpPower = 50
		human.JumpHeight = 7.2
		human.WalkSpeed = 16
	end
end)

It quite works in short, just does not synchronizes with the bounce and does not change its value to normal if the ballon.Parent.Parent == nil

That’s because Jumping is an Event, you need to create an event connection like what you did with Touched

https://developer.roblox.com/en-us/api-reference/event/Humanoid/Jumping

And also, for checking a change in parent, use AncestryChanged

Though I don’t know if this is the best route to do all of this with a touched event, I still think it’s better to use these with a mix of equipped and unequipped events on the tool so that way it’s easier to check whe nthe balloon is unequipped and easier to set up the giving of stat changes and jumping check

1 Like