Help with Storage Full script

Hello peeps, im makin a project and i want help with storage full so people dont spam i want to make when the currency = MainStorage like 25/25 FULL the function that gives points stop workin until currency = 0 or < Storage ``here’s the script here’s the script.

local player = game.Players.LocalPlayer
local Storage = player.BackpackShop.BackpackV


script.Parent.LiftPan.OnServerEvent:Connect(function()
	local eggs = game.Players[script.Parent.Parent.Name].leaderstats.Eggs
	eggs.Value = eggs.Value + script.Parent.Eggs.Value -- i want to turn this off
	if eggs.Value == Storage.Value then
		   --<< i want help at this point how can i turn off the currency giver
	end
end)

if u have any other idea to make when currency = storage 25/25 it stop the currency giver leave a comment down below :3

Put the if statement before adding the points to the eggs.Value and make it return nil to stop the function from executing.

local player = game.Players.LocalPlayer
local Storage = player.BackpackShop.BackpackV


script.Parent.LiftPan.OnServerEvent:Connect(function()
	local eggs = game.Players[script.Parent.Parent.Name].leaderstats.Eggs
	
	if eggs.Value == Storage.Value then
		   return -- stops the function from executing 
	end
	
	eggs.Value = eggs.Value + script.Parent.Eggs.Value -- i want to turn this off
	
end)
1 Like

but it doesnt give points now … i want at the moment when Currency = the Storage The script stop giving points u know… its like storage full thing

You can use math.clamp for this, as follows:

local player = game.Players.LocalPlayer
local Storage = player.BackpackShop.BackpackV

script.Parent.LiftPan.OnServerEvent:Connect(function()
	local eggs = game.Players[script.Parent.Parent.Name].leaderstats.Eggs
	eggs.Value = math.clamp(eggs.Value + script.Parent.Eggs.Value,0,Storage.Value)
end)
2 Likes

It should stop giving points to the player when the currency is equal to the storage? I don’t think I understand what you’re trying to explain, can you elaborate a bit more?

You could use something like

Make sure it’s a local script or it will NOT work :slight_smile:

If StorageName is equal to Storage then
print(“Storage full”)
Game.Players.LocalPlayer:WaitForChild(“PlayerGui”).GuiName.Visible = true
— This tells the user he’s out of storage

You could make a sell feature which puts storage back to 0

i already have this on but reason why i made this cuz people can spam with autoClicker and break the system and get points more than the storage require u know ;-;

Script.Parent.ScriptName.Disabled = true