Why is equipped always false?

I made this script to change a value in the player’s head when the user clicks the mouse. The remote event is fired when they do.
It was working with the tool unequipped so I thought I would add some code to make it only work when the tool is equipped. The only problem is that the equipped value is always false. I’m very confused!
It is late so I might be missing something obvious

local CD = false
local animId = 6783774822

local equipped = false



script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr)
	print(equipped)
	if CD == false and plr.Character.Head:FindFirstChild("Damage") then
		if equipped == true then
			CD = true
		    	
			plr.Character.Head.Damage.Value = true
			print("Bite")
			wait(1.5)
			CD = false
			plr.Character.Head.Damage.Value = false
		end
	end
end)


script.Parent.Equipped:Connect(function()
	equipped = true
end)

script.Parent.Unequipped:Connect(function()
	equipped = false
end)

Maybe because you didn’t define the Unequipped event.

I think its supposed to be an event already in the tool

if script.Parent.Equipped == true then

equipped = true

end

if script.Parent.Unequipped == false then

equipped = false

end

Hopefully this works!

you didn’t define these events.

script.Parent.Equipped:Connect(function()
	equipped = true
end)

script.Parent.Unequipped:Connect(function()
	equipped = false
end)

you can do something like this:

if script.Parent.Equipped == true then
equipped = true
else
equipped = false
end

Tool.Equipped and Tool.Unequipped are events, not properties.
What you could do is try and define the tool as its own variable, like local Tool = script.Parent.

your code will not work because you typed it fast and didn’t realize that

script.Parent.Equipped == true

will be the same thing as

script.Parent.Unequipped == false 

also I don’t think that “Equipped” and "Unequipped " are valid members of tool

Thats what I said.

And I looked at the Api’s but Im still not sure if thats the correct way to use it.

@itsXtimes @JostosYT @FunnelDeveloper Please don’t send a solution that will otherwise confuse the OP. As @1phasephasephase says, Unequipped and Equipped are events, not propeties.

@itsXtimes They are not member of tool, but rather an event. Please make a research before sending solutions.

@jsnotlout1 Based on the content of the script, I assume this is a server script. It is suggested to use a local script in a tool instead of a server script to reduce the load in the server.

I legit said that it wasn’t defined.

I checked on the internet and:

tool.Equipped:Connect(function()

end)

tool.Unequipped:Connect(function()

end)

are actually functions…
so maybe try debugging

tool.Equipped:Connect(function()
print("equipped")
equipped = true
end)

tool.Unequipped:Connect(function()
print("Unequipped")
equipped = false
end)

Those aren’t functions, those are events that are connected to functions that are called when the event is raised.

1 Like

An event is an object itself. It does not pertain to conditionals (true/false), numbers and strings. It is its own object which a unique function.

This is not how an event works. An event is an object that can be connected and be fired when conditions are met. Equipped fires when the character equips a tool has that Equipped event.

Maybe if you could solve the real issue here, and not act like you know everything, this would be solved.

why do you need to correct you know what I mean…

@FunnelDeveloper @itsXtimes We are correcting you guys so that confusion like this won’t happen in another post.

Well, I’ll just stop correcting now. It should be enough to clear the confusion.

@OP, if the equipped variable is still false, it means that the event didn’t fire. In your script, the only condition that the variable will change is when an event fired. It would really be helpful if you could send what type of script it is, where you put the tool, and much more.

@Quwanterz I just typed fast and typed “function” instead of “event”.
I am pretty sure you know what I mean.
I’m not so new to scripting…

anyways, did you tried debugging?

The tools events are firing. This is a weird issue

I clone the tool from serverstorage every round, maybe that breaks it?