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

Can't take away from number values?

The issue is whenever I run this the tries doesn't go down... no errors whatsoever.

function c()
	
local ctc= math.random(1,3)

local try = script.Parent.Parent.Tries.Value
if try > 0 then
	if ctc == 1 then
		try = try - 1
		script.Value.Value ="test1"
		
	elseif
		ctc == 2 then
		try = try - 1
		script.Value.Value = "test2"
	elseif
		ctc== 3 then 
		try = try - 1
		script.Value.Value = "test3"

	end
	elseif try <= 0 then
	try = 0
	script.Parent.TextButton.Text = "No tries left!"
end

end












script.Parent.TextButton.MouseButton1Click:connect(function()
  c()
script.Parent.TextLabel.Text = script.Value.Value
end)

1 answer

✓ Accepted answer

This is because when you assign the value of Tries to try, it's saving it as a number, not a reference to Tries.Value. This means it won't change the value of Tries when changing try, so you'll have to either manually assign it, or create a function for doing so. Example:

-- Add something to tries, or just call it and add one by default.
local function addTries(n)
	Tries.Value = Tries.Value + (n or 1)
end

-- Subtract something to tries, or just call it and subtract one by default.
local function subTries(n)
	Tries.Value = Tries.Value - (n or 1)
end

addTries() -- Add one
subTries() -- Remove one

Otherwise, you'd manually assign the instruction:

if condition then
	Tries.Value = Tries.Value - 1
elseif other then
	Tries.Value = Tries.Value + 1
end

If you have any questions, just let me know.

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