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

How to Check if player is wearing a certain accessory?

I want to change "damage" if player is wearing an accessory. No idea how to check if player is wearing accessory but tried this.

local Player = game.Players.LocalPlayer
repeat wait() until Player.Character~= nil
local Char = Player.Character

if Char:FindFirstChild("MagicTopHat")~= nil then
	damage = damage * 50
end

This is a localscript inserted into starterpack.

Any help would be appreciated. Thanks :D

3 comments

0

if Char:FindFirstChild("MagicTopHat")~= nil then 6 damage = damage * 50 7 end try using if Char.MagicTopHat then damage = damage * 50 end

0

Sorry, i don't know how to use markup text for the code

0

null * 50 ? , I think not .

1 answer

✓ Accepted answer

Every accesory have a unique mesh and the mesh has a unique ID. You can check if the mesh is using a certain ID and that's how you figure out what accessory it is. You can also do this for shirts, pants, and T-shirts.

Char = game:GetService("Players").LocalPlayer
damage = 10

if Char:FindFirstChild("MagicTopHat") then
	if Char.MagicTopHat:FindFirstChild("Handle") then
		if Char.MagicTopHat.Handle:FindFirstChild("Mesh") then
			if Char.MagicTopHat.Handle.MeshId == "" then -- insert mesh Id here
				damage = damage * 50
			end
		end
	end
end

I went to make sure that it could find the accessory's handle and mesh in case it was renamed or so. The default name for a Accessory's part is always Handle.

3 comments

0

Hehe give me a little bit to check if this works. Roblox Studio Pulled a didn't save so now I have to restart the script from scratch :D

0

Didn't work. Found Another way to change damage. Im accept anyways

0

I meant accessory.

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