local player = script.Parent.Parent.Parent.Parent.Parent.Parent Cost = 5 function checkForChocolateMilk() local found = false for i, v in pairs(player.Backpack:GetChildren()) do if v.Name == "ChocolateMilk" then found = true end end for i, v in pairs(player.Character:GetChildren()) do if v.Name == "ChocolateMilk" then found = true end end if found == true then return true else return false end end script.Parent.MouseButton1Click:Connect(function() local leaderstats = player:FindFirstChild("leaderstats") if leaderstats then local Points = leaderstats:FindFirstChild("Points") end local Points = leaderstats:FindFirstChild("Points") if Points then local hasChocolateMilk = checkForChocolateMilk()() if Points.Value >= Cost and hasChocolateMilk == false then Points.Value = Points.Value - Cost local ChocolateMilk = game.ServerStorage.ChocolateMilk:Clone() ChocolateMilk.Parent = player.Backpack end local found = false for i, v in pairs(player.Backpack:GetChildren()) do if v.Name == "ChocolateMilk" then found = true end if found == true then script.Parent.Parent.Parent.ChocolateMilkOwned.Visible = true script.Parent.Roundify.ImageColor3 = Color3.fromRGB(255, 44, 47) end end end end)
Seems like you're trying to only set Points if leaderstats exists, which is not what your code is currently doing. Looks like you have some confusion in general about if blocks. Change the MouseButton function to something like this:
script.Parent.MouseButton1Click:Connect(function() local leaderstats = player:FindFirstChild("leaderstats") if leaderstats then local Points = leaderstats:FindFirstChild("Points") if Points then local hasChocolateMilk = checkForChocolateMilk() if Points.Value >= Cost and hasChocolateMilk == false then Points.Value = Points.Value - Cost local ChocolateMilk = game.ServerStorage.ChocolateMilk:Clone() ChocolateMilk.Parent = player.Backpack end local found = false for i, v in pairs(player.Backpack:GetChildren()) do if v.Name == "ChocolateMilk" then found = true break end end if found == true then script.Parent.Parent.Parent.ChocolateMilkOwned.Visible = true script.Parent.Roundify.ImageColor3 = Color3.fromRGB(255, 44, 47) end end end end)
You also should break out of the for look when what you want is found, as seen above
In your code, you check if leaderstats has been created and then create the Points IntValue, however directly after it you check for points outside of the statement, therefore nullifying the purpose of the if statement to catch the potential error.
tl;dr: remove line 33