I’ve read the post on the Community Tutorials “Collection Service in a nutshell”
by @flamenco_687 and I kinda understand on what he meant of looping
through tagged parts and adding a function to em but now I’m having problems of converting a meteor script into CollectionService so I won’t have to duplicate the script and paste into the part so heres the code
local c = game:GetService("CollectionService")
for _, i in pairs(c:GetTagged("Meteorite")) do
function OnTouch()
local e = Instance.new("Explosion")
local CEP = game:GetService("ServerStorage").CustomExplosionP:Clone()
CEP.Parent = workspace
CEP.Position = i.Position
e.BlastPressure = 2800000
e.BlastRadius = 85
e.Parent = workspace
e.Position = i.Position
--If you want to add sound on explosion
local Bsound = Instance.new("Sound")
Bsound.SoundId = "rbxassetid://440431180"
Bsound.Volume = 4
Bsound.PlaybackSpeed = 0.8
Bsound.PlayOnRemove = true
Bsound.Parent = i
i:Destroy()
end
i.Position = Vector3.new(math.random(-2000,2000),math.random(850,1000),math.random(-2000,2000))
i.BP.Position = Vector3.new(math.random(-500,500),-1,math.random(-500,500))
i.Touched:Connect(function(p)
if (p.CanCollide == true) then -- kinda out of topic but when do i use these brackets in the future of making another if statement? Tried it without the brackets and nothing changed
OnTouch() -- somehow the function doesnt run when i called it :/
end
end)
end
Any help?