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 4 years ago

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

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

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 — 4y

2 answers

Log in to vote
1
Answered by 4 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.

01script.Parent.Touched:Connect(function(hit)
02    if game.Players:GetPlayerFromCharacter(hit.Parent) then
03        local RootPart = hit.Parent:FindFirstChild("HumanoidRootPart")
04 
05        if RootPart then
06            repeat
07                script.Parent.Value = script.Parent.Value + 1  
08            until
09            script.Parent.Value == 20
10        end
11    end
12end)
0
just use val += val2 WideSteal321 773 — 4y
1
so much more simple than typing val = val + val2 WideSteal321 773 — 4y
0
No, I switched it up and, repeat script.Parent.Value + 1 until script.Parent.Value == 20, that is better. Nicholas1088 169 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

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

Answer this question