Detect tool's equip

Hello my fellow developers,

I have a script in my Startergui that makes the arms visible in first person for r6

local player =  game:GetService("Players").LocalPlayer
local character = player.character or player.characterAdded:Wait()
 
game:GetService("RunService").RenderStepped:Connect(function()
 for i, part in pairs(character:GetChildren())do
  if string.match(part.Name, "Arm")or string.match(part.Name, "Hand") then
   part.LocalTransparencyModifier = 0
  end
 end
end)

How do i detect the tool equip so that i can set the transperncy to 0? It creates a bug where 2 hands are being displayed at once

1 Like

You can use the function Tool:Equipped()

local Tool = Character.Tool -- You can set which tool

Tool.Equipped:Connect(function()
-- do function here
end)
1 Like

Your code is basically asking to loop through all the parts in your children, and if its name has the word Arm or Hand in it, you set that part’s LocalTransparencyModifier to 0.

And you have two arms/hands, the left and the right.

You can see the problem already. :stuck_out_tongue:

Here is the script I use in my game:

local CharacterPartNames = {
	"LeftHand";
	"LeftUpperArm";
	"LeftLowerArm";
	"RightHand";
	"RightUpperArm";
	"RightLowerArm";
}

local MakeArmNonTransparent
Tool.Equipped:Connect(function()
	MakeArmNonTransparent = game:GetService("RunService").RenderStepped:Connect(function()
		for _, playerpart in pairs(character:GetChildren()) do
			if playerpart:IsA("BasePart") and table.find(CharacterPartNames, playerpart.Name) then
				playerpart.LocalTransparencyModifier = 0
			end
		end
	end)
end)

Unequipped function:

Tool.Unequipped:Connect(function()
	MakeArmNonTransparent:Disconnect()
end

I don’t know if this is the best way to do it but it works. Also, I am pretty sure that I just stole the renderstepped thing from the devforum so credits to whoever originally made it.

Edit: I am pretty sure that I got some parts of this script from this post.

No, my tool automatically shows the arms in first person, i just needed to figure out how to make it so that the tool disables the firstperson without a tool

How do i set it to the toolname? Sorry i am kind of new

You should probably put your localscript under the tool itself and then set the tool variable to script.Parent.

good idea, thank you very much

It works guys!! Thanks!!! :blush::blush::blush::blush::blush::blush:

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