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

I need to set a limit on the value?

So, Ya im trying to set a limit so i cant the units value cant get over 50 this is wat i got so far . I dont know why its not working thats the hole script and this the part with "If Units.Value == 50 then Units.Value = Units.Value - 10" its there the limit im trying to set is not working.

Cash = Player.leaderstats.Cash
Units = Player.leaderstats.Units

function onClick()
	if Cash.Value >= 20 then
		Cash.Value = Cash.Value - 20
		Units.Value = Units.Value + 1
			local Barbarian = game.Lighting.Barbarian:clone()
	end
	if Units.Value == 50 then
		Units.Value = Units.Value - 10
	end
	if Cash.Value <= 20 then
		script.Parent.NotEnough.Visible = true
		wait(2)
		script.Parent.NotEnough.Visible = false
	end
end

script.Parent.MouseButton1Click:connect(onClick)

3 comments

0

Change line 10 to: "if Units.Value > 50 then" (without the quotation marks, ofc). Also fix your grammar so others can understand you better.

0

I'd suggest checking your grammar on this question. I wish I could answer it, but you've made some grammar errors.

0

got it working thanks "TheDeadlyPanther"

1 answer

Maybe use

Cash = Player.leaderstats.Cash Units = Player.leaderstats.Units

function onClick()
    if Cash.Value >= 20 then
        Cash.Value = Cash.Value - 20
        Units.Value = Units.Value + 1
            local Barbarian = game.Lighting.Barbarian:clone()
    elseif Cash.Value <= 20 then
        script.Parent.NotEnough.Visible = true
        wait(2)
        script.Parent.NotEnough.Visible = false
    end
    if Units.Value == 50 then
        Units.Value = Units.Value - 10
    end
end

script.Parent.MouseButton1Click:connect(onClick)

They are both about Cash so I elseif'ed it.

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