Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I add up values?

Asked by 3 years ago
Edited 3 years ago

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.

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago
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

0
When I tested the script, it increases the value whenever it's equipped. I wanted it to increase the value when the player CLICKS(Activates) the tool. Dragonboy99711 5 — 3y
0
Great, then don't be a script kitty, and move the obvious addition line to where it needs to be Ziffixture 6913 — 3y
0
Yes ^, however it seems I cannot get around the :Activated() event, so I made a further revision in the script above which should make it so the value is increasing when the tool is equipped and is clicked. gioreyes1234 5 — 3y
0
I'm sorry for being one- I had no idea I was acting like that. Yes, I tried switching the addition line, but it doesn't work either- Dragonboy99711 5 — 3y
View all comments (3 more)
0
Zach, try to use the updated code above. gioreyes1234 5 — 3y
0
I'm afraid it still doesn't work ^, I tried clicking a bunch of times. Dragonboy99711 5 — 3y
0
Works when I do it. gioreyes1234 5 — 3y
Ad

Answer this question