Heya guys, I wanted to make a tool that increases a value whenever activated, this is the script I tried. (I used Roblox's script template.)
local tool = script.Parent local function onEquip() end local function onUnequip() end local function onActivate() game.Players.LocalPlayer.Character.Humanoid.BodyWidthScale.Value = end local function onDeactivate() end tool.Equipped:Connect(onEquip) tool.Unequipped:Connect(onUnequip) tool.Activated:Connect(onActivate) tool.Deactivated:Connect(onDeactivate)
For example, the value is 1. When the tool is activated, it increases to 2. And then when it is activated again, it's 3 and so on.
local tool = script.Parent local UserInputService = game:GetService("UserInputService") local Value = 1 --Starting value function onEquip() UserInputService.InputChanged:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 then --This makes it so it detects when a mouse button is clicked. onActivate() end end) end function onUnequip() end function onActivate() Value = Value + 1 --Adding a number to the value when being eqquiped. game.Players.LocalPlayer.Character.Humanoid.BodyWidthScale.Value = Value -- Updating the "BodyWidthScale.Value" to the new, and updated value. end function onDeactivate() end tool.Equipped:Connect(onEquip) tool.Unequipped:Connect(onUnequip) tool.Activated:Connect(onActivate) tool.Deactivated:Connect(onDeactivate)
Explanations are above