So, I’m tryna make a pizza script where if you touch an npc you get a certain amount of money. For example, pizza with ingredients = 20 dollars, pizza with only cheese = 15 dollars, pizza with nothing = 10 dollars. However, when the pizza doesn’t contain both the cheese and the sauce, the item is not destroyed and the money isn’t given to the player.
pizza.Touched:Connect(function(hit)
print(hit)
if hit.Parent.Name == "Noob" then
local player = game.Players.LocalPlayer
if tool.Name == "Pizza" then
player.leaderstats.Money.Value += 10
if pizza.Sauce then
player.leaderstats.Money.Value += 5
end
if pizza["Cooked Cheese"] then
player.leaderstats.Money.Value += 5
end
tool:Destroy()
end
should be player.leaderstats.Money.Value = player.leaderstats.Money.Value + 15
tbh i cant really do much fixing or debugging espeically with the small script you gave me but this is my solution
local tool = pizza:FindFirstChild("PizzaTool")--lil dude Obvously you gotta put YOUR TOOL RIGHT NAME
pizza.Touched:Connect(function(hit)
print(hit)
local character = hit.Parent
if character and character:IsA("Model") and character.Name == "Noob" and tool and tool.Name == "Pizza" then
local hasSauce = pizza:FindFirstChild("Sauce")
local hasCheese = pizza:FindFirstChild("Cheese")
if hasSauce and hasCheese then
character:FindFirstChild("leaderstats").Money.Value = character:FindFirstChild("leaderstats").Money.Value + 20
elseif hasCheese then
character:FindFirstChild("leaderstats").Money.Value = character:FindFirstChild("leaderstats").Money.Value + 15
else
character:FindFirstChild("leaderstats").Money.Value = character:FindFirstChild("leaderstats").Money.Value + 10
end
tool:Destroy()
end
end)
I don’t really understand the behaviour you would like to see when the pizza has no sauce and also no cheese.
If you want nothing to happen when the pizza has none of both then you can skip the entire pizza block code by writing it like this
if tool.Name == "Pizza" and (pizza.Sauce or pizza["Cooked Cheese"]) then
-- it's a pizza that has sauce or cheese or both
-- the rest of the original code here
end
Did you mean this or what did you mean by “pizza with nothing = 10 dollars”?
Originally you said pizza with nothing = 10 dollars and also “However, when the pizza doesn’t contain both the cheese and the sauce, the item is not destroyed and the money isn’t given to the player”
So by this did you mean that you get just 10 dollars for an empty pizza (without a bonus for ingredients) and it also doesn’t get destroyed?
so, if the pizza has both cheese and sauce, you will get the 20 dollars, if you are missing either the cheese or the sauce, no money is given to the player.