How would I go about making a grocery list? So, I have made a script that makes a folder which is the list and values which are the items the player needs to collect, the value would start at a certain number lets say 3 so the player would need to collect 3 apples so they can complete the list. I don’t know if there is an easier or better of doing this because I am struggling why my code doesn’t work.
If anyone has any suggestions on how to make a better grocery list please say, thanks in advance!
Script that subtracts fruit from value
local Players = game:GetService("Players")
script.Parent.Touched:Connect(function(otherPart)
local char = otherPart.Parent
local player = Players:GetPlayerFromCharacter(char)
if player then
local shoppingList = player:FindFirstChild("List")
local apple = shoppingList:FindFirstChildOfClass("Apple")
if apple then
if apple.Value > 0 then
apple.Value -= 1
script.Parent:Destroy()
end
end
end
end)
local apple = shoppingList:FindFirstChild("Apple")
when the part is only meant to be touched once, you should immediately disconnect the connection or only connect it once, or else the players might get multiple apples from one apple
local Players = game:GetService("Players")
script.Parent.Touched:Connect(function(hit)
local char = hit.Parent
local player = Players:GetPlayerFromCharacter(char)
if player then
local shoppingList = player:FindFirstChild("List")
-- check the name of the item you're touching so you don't need to open all the scripts to rename stuff
local Item = shoppingList:FindFirstChild(script.parent.Name)
if Item then
if Item.Value > 0 then
Item.Value -= 1
script.Parent:Destroy()
end
end
end
end)
Yeah I forgot to copy FindFirstChild correctly but even with that fix it doesn’t work, how would actually make it check for the apple value? I think that is the main problem.