Script:
-- Variables
local eggs = game.ReplicatedStorage.Eggs
local spawns = game.Workspace.EggSpawns
amnt = 50
-- Code
while wait(2) do
local eggsTable = eggs:GetChildren()
local randomEgg = eggsTable[math.random(1,#eggsTable)]
local spawnsTable = spawns:GetChildren()
local randomSpawn = spawnsTable[math.random(1,#spawnsTable)]
local eggClone = randomEgg:Clone()
eggClone.Parent = game.Workspace.SpawnedEggs
eggClone.Position = randomSpawn.Position + Vector3.new(0,20,0)
eggClone.Anchored = false
eggClone.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
game.ReplicatedStorage.FoundEgg:FireClient(plr,eggClone.Name)
local h = hit.Parent:FindFirstChild("Humanoid")
if (h~=nil) then
local thisplr = game.Players:findFirstChild(h.Parent.Name)
if (thisplr~=nil) then
local stats = thisplr:findFirstChild("leaderstats")
if (stats~=nil) then
local score = stats:findFirstChild("Points")
if (score~=nil) then
score.Value = score.Value + amnt
end
eggClone.Destroy()
end
end
end
end
end)
end
Basically the problem is that, after i touch the part the part doesnt get destroyed, (Im using a mesh as a Part.)