vosken
(vosken)
June 7, 2022, 8:28pm
#1
What do you want to achieve? When a player touches a part, the tool in his inventory get equipped
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 )
Valkyrop
(JustAGuy)
June 7, 2022, 8:32pm
#3
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 .
vosken
(vosken)
June 7, 2022, 8:51pm
#6
Alright, I’ll go check it out Thanks!
1 Like
vosken
(vosken)
June 7, 2022, 9:03pm
#7
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