How do I add a limit?

Local 1:

wait(0.3)
local player = game:GetService("Players").LocalPlayer
local ld = player:WaitForChild("leaderstats")

local rebirthButton = script.Parent.Parent.MainButtons.rebirthButton
local main = script.Parent.Parent.RebirthGui.Main
local tween = game:GetService("TweenService")

local wins = ld.Wins.Value
local rebirth = ld.Rebirth.Value

local function open()
	game:GetService("SoundService").click:Play()
	local Info = TweenInfo.new(0.15)
	local Tween = tween:Create(main, Info, {Position = UDim2.new(0.247, 0, 0.192, 0)})
	Tween:Play()

	game:GetService("Lighting").Blur.Enabled = true
	tween:Create(game.Workspace.CurrentCamera, TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {FieldOfView = 90}):Play()
end

local function close()
	game:GetService("SoundService").click:Play()
	local Info = TweenInfo.new(0.15)
	local Tween = tween:Create(main, Info, {Position = UDim2.new(0.247, 0, 1, 0)})
	Tween:Play()

	game:GetService("Lighting").Blur.Enabled = false
	tween:Create(game.Workspace.CurrentCamera, TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {FieldOfView = 70}):Play()
end

local function makeRebirth()
	if rebirth.Value == 0 then
		if wins.Value >= 500 then
			game:GetService("SoundService").Click:Play()

			rebirth.Value += 1
			wins.Value = wins.Value - 500
		end
	end
end

local function donateRebirth()
	game:GetService("MarketplaceService"):PromptProductPurchase(player, 1604253727)

	game:GetService("SoundService").Click:Play()
end

rebirthButton.MouseButton1Click:Connect(open)
rebirthButton.TouchTap:Connect(open)

main.close.MouseButton1Click:Connect(close)
main.close.TouchTap:Connect(close)

main.makeRebirth.MouseButton1Click:Connect(makeRebirth)
main.makeRebirth.TouchTap:Connect(makeRebirth)

Local 2:

wait(0.3)

local main = script.Parent.Parent.RebirthGui.Main
local player = game:GetService("Players").LocalPlayer

while wait(1) do
	if player.leaderstats.Rebirth.Value == 0 then
		main.progressBack.progressText.Text = player:WaitForChild("leaderstats").Wins.Value.. " / ".. 500
		main.progressBack.progressCurrent:TweenSize(
			UDim2.new(player:WaitForChild("leaderstats").Wins.Value / 500, 0, 0.857, 0),
			Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.5
		)
	end
end

So my question is how do I add a limit so that the line above can’t be long and go out of bounds?

2 Likes

Use math.clamp(value, min, max)

4 Likes

can I have the full code? please

main.progressBack.progressCurrent:TweenSize(
	UDim2.new(math.clamp(player:WaitForChild("leaderstats").Wins.Value / 500, 0, 1), 0, 0.857, 0),
	Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.5
)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.