holder = Instance.new("Model") holder.Parent = game.Workspace holder.Name = "Holder"
foodamount = Instance.new("IntValue") foodamount.Name = "FoodAmount"
game.Players.PlayerAdded:connect(function(plr)
foodamount.Parent = game.Players[plr.Name]
end)
while true do
food = Instance.new("Part")
food.BrickColor = BrickColor.Random()
food.Size = Vector3.new(1, 1, 1)
food.Position = Vector3.new(math.random(-499.3, 499.3), -7, math.random(-499.3, 499.3))
food.Parent = holder
food.Name = "Food"
food.CanCollide = false
food.Anchored = true
food.BackSurface = "SmoothNoOutlines"
food.BottomSurface = "SmoothNoOutlines"
food.FrontSurface = "SmoothNoOutlines"
food.LeftSurface = "SmoothNoOutlines"
food.RightSurface = "SmoothNoOutlines"
food.TopSurface = "SmoothNoOutlines"
wait(.01)
end
foods = game.Workspace:WaitForChild("Holder"):GetChildren()
for _,v in pairs(foods) do
v.Touched:connect(function(hit)
local parent = hit.Parent
if parent:IsA("Part") and parent.Name == "Food" then
if parent ~= nil then
parent:Remove()
end
elseif parent:IsA("Humanoid") then
if parent ~= nil then
local findfood = hit.Parent:findFirstChild("Food")
if parent ~= nil then
local player = parent.Parent
local getValue = game.Players[player.Name]:WaitForChild("FoodAmount")
getValue.Value = getValue.Value + 1
end
end
end
end)
end
Nothing happens when a Player touches a "food" part, why?
