So you probably have not heard of events. Events are basically where roblox listens into specific events, such as seeing if the tool is equipped or unequipped. There is specific events depending on the context. Also you can put your script under the tool instead of where you putted it.
1 | script.Parent.Equipped:Connect( function () |
So when a player equips the tool, the event will fire and will run any code inside it. Also script.Parent
is the same as game.Workspace.Tool
. Another event you should notice is the unequipped event.
1 | script.Parent.Unequipped:Connect( function () |
You can either connect a named function or use an anonymous function (which I currently used.) You can find more information in the wiki about how to use events right here.
So I'll change the script to what you wanted.
1 | script.Parent.Equipped:Connect( function () |
5 | script.Parent.Unequipped:Connect( function () |