Enquip a certain item when you step on a part

  1. What do you want to achieve? When a player touches a part, the tool in his inventory get equipped

  2. What is the issue? I cannot get the tool in this case called Flash Light equipped when walking on the part

This is what I got,

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then

	local player = game.Players:GetPlayerFromCharacter(hit.Parent) 

	if player then 
		-- Not sure how to make this work
	end

end

end)

You can just say:

local humanoid = player.Character.Humanoid

humanoid:EquipTool(ToolName)

You could use EquipTool( provide the tool in the ‘()’.)

Or alternatively move the tool to the character.

Here is the developer page for Humanoid:EquipTool.

Alright, I’ll go check it out Thanks!

1 Like

Hello so I tried to do this

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then

	local player = game.Players:GetPlayerFromCharacter(hit.Parent) 
	local humanoid = player.Character.Humanoid

	humanoid:EquipTool("Flash Light")

end

end)

But now I get the Error Unable to cast value to Object
Do you know how to solve this? I tried checking out Humanoid:EquipTool (roblox.com)

You are using a string instead of an instance, you need to specify player.Backpack[“Flash Light”]
This is just an example, you also need to check if the flashlight is in their backpack beforehand, and check if they already have a flashlight equipped so it doesn’t duplicate or whatever