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

How do I make something that plusses a value?

Asked by 3 years ago

Sorry for unclear question but, I am trying to make something where it detects if its been touched by a tool

script.Parent.Touched:Connect(function(Hit)
    if Hit.Parent.Name == '(name)' then
    end
end)

but after it hits it, I want it to plus a value, and after the value reaches 20, it doesn't plus it anymore, anybody able to help?

1
use val += val2 WideSteal321 773 — 3y

2 answers

Log in to vote
1
Answered by 3 years ago

You can make an int value, and then if it's touched then that value = value + 1, you can repeat this action using the repeat function in Roblox Studio and then use the Until function in Roblox Studio. If the value is 20 then that Until function will stop anything.

script.Parent.Touched:Connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        local RootPart = hit.Parent:FindFirstChild("HumanoidRootPart") 

        if RootPart then
            repeat
                script.Parent.Value = script.Parent.Value + 1   
            until
            script.Parent.Value == 20
        end
    end
end)
0
just use val += val2 WideSteal321 773 — 3y
1
so much more simple than typing val = val + val2 WideSteal321 773 — 3y
0
No, I switched it up and, repeat script.Parent.Value + 1 until script.Parent.Value == 20, that is better. Nicholas1088 169 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

If you want it to be tocuhed by a tool use this script:

function tch(h)
if (h.Parent.Name == "ToolName") then
script.Parent.Value = script.Parent.Value +1
    end
    end
script.Parent.Touched:connect(tch)

Answer this question