Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to detect if a player has tools using v.ClassName ?

I have this invisibility power-up that makes players invisible, but the tool the player is holding doesn't. therefore I made this script but it doesn't work. it's only a little part of the script:

	 for _,v in pairs(game.Players:GetChildren(player.Backpack:GetChildren())) do
			if v.ClassName == "Tool" then
			v.Handle.Transparency = 1

this is the whole script

local debounce = false

function onTouched(hit)
    if hit.Parent then
        local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
        if player ~= nil then
	        if debounce then return end

	debounce = true
            script.Parent.ScreenGui:Clone().Parent = player.PlayerGui

			script.Parent.PickUp:Play()
			script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,100,0)
			player.Character.Torso.Transparency = 1
			player.Character.Head.Transparency = 1
			player.Character["Left Arm"].Transparency = 1
			player.Character["Right Arm"].Transparency = 1
			player.Character["Left Leg"].Transparency = 1
			player.Character["Right Leg"].Transparency = 1
			player.Character.Torso.Trail.Enabled = false
			player.Character.Head.Face.Transparency = 1
		 for _,v in pairs(game.Players:GetChildren(player.Backpack:GetChildren())) do
			if v.ClassName == "Tool" then
			v.Handle.Transparency = 1
				
			

		
wait(10)
						
--will do the rest

wait(200)
	debounce = false

	script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,-100,0)
				end
			end
        end
    end
end
script.Parent.Touched:connect(onTouched)

every thing works BUT the tool transparency modifier, any help?

5 comments

0

Do you include any other model, mesh, part,... in the tool?

0

i just want to grab the Handle of the tool and change its transparency. there are indeed other children in the tool, but those i dont need to modify.

0

Theres only 1 union in the tool called Handle, no other 3D objects.

0

Wait, you have a player instance in the first place, why you need to loop though the table of players.

0

And why you need to check the children of the backpack is a tool or not. It better to check is that the "invisible tool", so the player can't not be invisible with the different tool in the backpack.

1 answer

When you use the method :GetChildren you do not put any argument inside of it, if you want to hide the player's tools you can do this

local debounce = false

function onTouched(hit)
    if hit.Parent then
        local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
        if player ~= nil then
            if debounce then return end

    debounce = true
            script.Parent.ScreenGui:Clone().Parent = player.PlayerGui

            script.Parent.PickUp:Play()
            script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,100,0)
            player.Character.Torso.Transparency = 1
            player.Character.Head.Transparency = 1
            player.Character["Left Arm"].Transparency = 1
            player.Character["Right Arm"].Transparency = 1
            player.Character["Left Leg"].Transparency = 1
            player.Character["Right Leg"].Transparency = 1
            player.Character.Torso.Trail.Enabled = false
            player.Character.Head.Face.Transparency = 1
         for _,v in pairs(player.Backpack:GetChildren()) do
            if v.ClassName == "Tool" then
            v.Handle.Transparency = 1

wait(10)

--will do the rest

wait(200)
    debounce = false

    script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,-100,0)
                end
            end

        end
    end
end
script.Parent.Touched:connect(onTouched)

Wait! That's not all, when you equip a tool it gets cloned to the player's character so you also have to do that in the character so before the loop to hide all backpack's tools do this

for _,v in pairs(player.Character:GetChildren()) do
      if v:IsA("Tool") then
-- Note: You can use :IsA() function to check the classname too
v.Handle.Transparency = 1
      end
end

Well that's it! If this helped mark this as the answer. :D

This discussion is preserved as it was. New answers, comments, and votes are closed.