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

Anyway to make the player's hat/part disappear?

Is there anyway to make this local script (in a tool) target that player and edit the parts I gave?

local Playerss = game:GetService("Players")

Playerss.Character.G.Transparency = 1
Playerss.Character.Part1.Transparency = 1
Playerss.Character.Part2.Transparency = 1
Playerss.CharacterPart3.Transparency = 1
Playerss.Character.Part2.Transparency = 1

for ex: If I equip a tool, it makes the hat/part goes invisible from my character.

1 comment

0

Make a hat remover and put it inside of a tool and make it big enough to cover the player so their hat goes away? Make sure the part is cannot collide.

1 answer

✓ Accepted answer

Yes, you will, however, also need a RemoteEvent to make the changes on the server, so other players can see it.

LocalScript in Tool

local localplayer = game.Players.LocalPlayer
local character = localplayer.Character or localplayer.CharacterAdded:wait()
local TransparencyEvent = script:WaitForChild('TransparencyEvent')
local Tool = script.Parent

local WhiteList = {
	['Part1'] = true;
	['Part2'] = true
}

-- Index parts to a table, so we only need to 
	-- scan the player once
local Parts = {}

-- If Child is a BasePart and it's in the WhiteList, add to table.
local function PreCheck(Object)
	if Object:IsA("BasePart") or Object:IsA('MeshPart') then
		-- Ignore HumanoidRootPart
		if Object ~= character.PrimaryPart and WhiteList[Object.Name] then
			table.insert(Parts, Object) 
		end
	end
end

-- Recurse character when we first load
for _, Object in pairs ( character:GetDescendants() ) do 
	PreCheck(Object)
end

Tool.Equipped:Connect(function()
	TransparencyEvent:FireServer(Parts, 1)
end)

Tool.Unequipped:Connect(function()
	wait()
	-- This is so when we swap tools, it doesn't set to 0.
	if not character:FindFirstChildOfClass('Tool') then 
		TransparencyEvent:FireServer(Parts, 0)
	end
end)

-- Anything gets added to the character will be caught
character.DescendantAdded:Connect(PreCheck)


Script inside of LocalScript

local TransparencyEvent = Instance.new("RemoteEvent")
TransparencyEvent.Name = 'TransparencyEvent'

-- The Player who fired the event is always the first argument in a RemoteEvent
TransparencyEvent.OnServerEvent:Connect(function(Player, Parts, newTransparency)
	for i,v in pairs ( Parts ) do 
		v.Transparency = newTransparency
	end
end)

TransparencyEvent.Parent = script.Parent

11 comments

0

for the "Add all necessary Parts" like what do you mean by that? The Item that is in the character?

0

Which line?

0

My bad! The page didn't load correctly, thus showing me the old post

0

Sorry If i keep notifying you, but is there a way for it to select multiple parts in that character? Like how my code is with "Part1" "Part2" etc...

0

Yes, I added a dictionary and edited line 19.

0

Kept on receiving: Infinite yield possible on 'Workspace.TheBuliderMC.LocalScript:WaitForChild("HatTransparencyEvent")'

0

Did you put a Script in the LocalScript, then put the Second part of my code in that script?

0

Yes sir

0
0

I did that, and it's still giving me that error. Does the "Part" need to be a hat because it was a part that was welded to the head? And I have a slight feeling that StarterCharacter(Custom Character) breaks it?

1

NVM! I found out what I was doing incorrectly! Thanks for your help!

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