Gui localscript not working

I’ve tried to make a script for a fridge, but it doesn’t work :(.

script.Parent.MouseButton1Click:Connect(function()
  if script.Parent.Quantity.Value > 0 then
	local plr = game.Players.LocalPlayer
	local tool = game.Lighting.Popsicle:Clone()
	script.Parent.Quantity.Value = script.Parent.Quantity.Value - 1
	tool.Parent = plr.Backpack
	script.Parent.Parent.Parent.Visible = false
  else
	script.Parent.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
	script.Parent.Text = "Out of Stock"
	wait(1)
	script.Parent.BackgroundColor3 = Color3.fromRGB(212, 212, 212)
	script.Parent.Text = "Popsicle"
	wait(0.5)
	script.Parent.Parent.Parent.Visible = false
  end
end)

It’s supposed to stop giving the tool if the quantity is equal to 0. But it just KEEPS GOING! It worked when I first ran the script then I published the game and visited the script later on. But now it’s not working.

2 Likes

Is script.Parent.Quantity an IntValue?

No, it’s a NumberValue. Should it be a IntValue?

Here’s a script I made to check if the player has a popsicle or not, hope it helps:

if plr.Backpack:FindFirstChild("Popsicle") or plr.Character:FindFirstChild("Popsicle") then -- check if the child "Popsicle" is in the player's backpack or character.

print("player has a popsicle already")

else

print("player does not have a popsicle so I will give the player one")

wait(1)

local tool = game.Lighting.Popsicle:Clone()

tool.Parent = plr.Backpack

end
1 Like

Better to be an IntValue because it’s always a full number. You aren’t giving people fractions of popsicles.

1 Like