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

How do I make a player wear an accessory when he/she equips a tool?

I have a tool named Pistol, and when equipped, it will check what team he/she(the player) is in. Suppose there are two teams, say, Red and Blue. If the script detects the player is in: Red - The player will be given the Comedy Accessory. Blue - The player will be given the Tragedy Accessory.

I think it uses the onEquip and onUnequip functions, onEquip because I want the script to detect when the tool is equipped, onUnequip because I want the accessory to be taken off when unequipped.

If this isn't possible, is there any other way I can do this with a similar effect?

1 comment

0

By the way, by similar effect I mean to have the accessory on while the tool is equipped.

1 answer

hey man, hope this helps. i don't usually help people like this, but if this helped, please accept my answer.

wait(1)
local Pistol = script.Parent --i think this script is in the tool, right? if not change it to where the pistol is.
local player = game.Players.LocalPlayer
local character = player.Character

Pistol.Equipped:connect(function()
	local Comedy = game.ServerStorage.ComedyAccessory:Clone() --make sure to parent the accessory into server storage, and name it 'ComedyAccessory'
local Tragedy = game.ServerStorage.TragedyAccessory:Clone() --do the same steps as the other accessory
if player.TeamColor == BrickColor.new('Bright red') then --change the teamColor exactly to the teamcolor you chose
Comedy.Parent = player.Character
end
if player.TeamColor ==  BrickColor.new("Bright blue") then --change the teamColor exactly to the teamcolor you chose
Tragedy.Parent = player.Character
end
Pistol.Unequipped:connect(function()
if player.TeamColor ==  BrickColor.new("Bright red") then --change the teamColor exactly to the teamcolor you chose
Comedy:Destroy()
end
if player.TeamColor ==  BrickColor.new("Bright blue") then --change the teamColor exactly to the teamcolor you chose
Tragedy:Destroy()
end
end)

end)

MAKE SURE THIS IS IN A LOCALSCRIPT PARENTED INSIDE OF THE PISTOL

9 comments

0

fixed it!

0

I'm testing it right now, only thing I don't get is line 2(it's a local script yet it's called script.)

0

I'll just try it anyways.

0

i understand your confusion about that. i did too when i began scripting. it doesn't matter what script it is (Module, Local, Script) there is no other word but script to complete a task like that. besides that, how is it working for you?

0

/\ Okay. I'm not that experienced with scripting, thanks.

0

if my script worked correctly, could you click the accept button under this chat please?

0

Wait, my pc's internet is broken. The animation cannot load, thus the thing is broken...

0

my script is not working?

0

your "Pc's internet" isn't broken if you were able to chat to me.

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