Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make something that plusses a value?

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 comment

1

use val += val2

2 answers

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)

3 comments

0

just use val += val2

1

so much more simple than typing val = val + val2

0

No, I switched it up and, repeat script.Parent.Value + 1 until script.Parent.Value == 20, that is better.

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.