game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local HRP = char:FindFirstChild('HumanoidRootPart')
local Humanoid = char:FindFirstChild('Humanoid')
local RainSpawner = Instance.new('Part', workspace)
RainSpawner.Name = 'RainSpawner'
RainSpawner.Anchored = true
RainSpawner.CanCollide = false
RainSpawner.Size = Vector3.new(60, 1, 60)
RainSpawner.Position = Vector3.new(HRP.Position.X , HRP.Position.Y + 34, HRP.Position.Z)
local Rain = coroutine.create(function()
while true do
task.wait()
local rainPart = Instance.new('Part', workspace)
rainPart.Name = 'Rain'
rainPart.Color = Color3.new(0, 0, 1)
rainPart.Size = Vector3.new(0.25, 0.25, 0.25)
rainPart.CanCollide = false
local x = RainSpawner.Position.X * 0.5
local y = RainSpawner.Position.Y * 0.5
local z = RainSpawner.Position.Z * 0.5
rainPart.Position = RainSpawner.Position + Vector3.new(math.random(0 - x, x), math.random(0 - y, y), math.random(0 - z, z))
game.Debris:AddItem(rainPart, 5)
end
end)
coroutine.resume(Rain)
while true do
task.wait()
if Humanoid.Health == 0 then
RainSpawner:Destroy()
end
RainSpawner.Position = Vector3.new(HRP.Position.X , HRP.Position.Y + 34, HRP.Position.Z)
end
end)
end)
So essentially my code is basically creating an area above the player from which the rain parts are going to fall from. The system already worked and was running without an issue, however, when I added the couroutine to actually make the rain parts fall I receive an error.
I would like to note that sometimes if I don’t make when I load I don’t immediately receive this error, but the code still doesn’t work in the way intended
Can y’all tell me why this bug is happening? I can try to fix it myself if y’all tell me the issue, but if i cant then slide the solution.