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

Tool adds/removes accessories even when unequipped?

I've found a temporary solution for a previous for a previous problem but a new issue has arisen. The tool does what I want it to, but the problem is that it does this even when the tool isn't equipped, which is an issue for obvious problems.

Here is the script:

local ISEquipped = false
local Mask = script:WaitForChild("Mask")
local Hood = script:WaitForChild("Hood")
script.Parent.Equipped:Connect(function()
	ISEquipped = true
end)
script.Parent.Unequipped:Connect(function()
	ISEquipped = false
end)

script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr)
	if plr.Character:WaitForChild("Humanoid") then
		if plr.Character:FindFirstChild("Mask") == nil then
			Mask:Clone().Parent = plr.Character
			Hood:Clone().Parent = plr.Character
		elseif plr.Character:FindFirstChild("Mask") then
			plr.Character.Mask:Destroy()
			plr.Character.Hood:Destroy()
		end
	end
end)

And the local script:

local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()

mouse.Button1Down:Connect(function()
	script.Parent.RemoteEvent:FireServer()
end)

The tool as it is in the workspace:

Tool

Script & Local Script & Remote Event

[Inside Script] Mask & Hood (Accessories)

I've tried a few different things but whatever I do either seems to break it or not change anything. Any and all help is appreciated.

2 answers

I think you forgot to fire if ISEquipped is true or false in the Server, try this:

local ISEquipped = false
local Mask = script:WaitForChild("Mask")
local Hood = script:WaitForChild("Hood")
script.Parent.Equipped:Connect(function()
	ISEquipped = true
end)
script.Parent.Unequipped:Connect(function()
	ISEquipped = false
end)

script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr)
	if plr.Character:WaitForChild("Humanoid") then
		if ISEquipped == true then
			if plr.Character:FindFirstChild("Mask") == nil then
				Mask:Clone().Parent = plr.Character
				Hood:Clone().Parent = plr.Character
			elseif plr.Character:FindFirstChild("Mask") then
				plr.Character.Mask:Destroy()
				plr.Character.Hood:Destroy()
			end
		else
			print("Tool is not equipped! Equip in order to work.")
		end
	end
end)

If there are mistakes, lemme know. ????

1 comment

0

It seems that even if the tool is equipped it'll still print("tool is not equipped"). Any idea why that might be?

Finally found the solution! Here it is:

  • Add a part to the tool named Handle [The part can be almost anything as long as it's unanchored and named Handle]
  • Change the script to this:
local ISEquipped = false
local Mask = script:WaitForChild("Mask")
local Hood = script:WaitForChild("Hood")
script.Parent.Equipped:Connect(function()
	ISEquipped = true
end)
script.Parent.Unequipped:Connect(function()
	ISEquipped = false
end)

script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr)
	if ISEquipped then
		if plr.Character:WaitForChild("Humanoid") then 
			if plr.Character:FindFirstChild("Mask") == nil then
				Mask:Clone().Parent = plr.Character
				Hood:Clone().Parent = plr.Character
			elseif plr.Character:FindFirstChild("Mask") then
				plr.Character.Mask:Destroy()
				plr.Character.Hood:Destroy()
else
			end
		end
	end
end)

Hope this will be helpful to anyone in the future!

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