Why do I get "Interval is empty"
at math.random even though my "playerCharacter.HumanoidRootPart.Position.Y"
returns a value clarified in the print before the line that’s producing the error:
Here’s the code:
local parts = {...}
local spawnRadius = script:GetAttribute("SpawnRadius")
local replicatedStorage = game:GetService("ReplicatedStorage")
local characterAddedEvent = replicatedStorage:WaitForChild("CharacterAdded")
local players = game:GetService("Players")
local playerCharacter = nil
local spawnRadiusObject = workspace.SpawnRadius
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
playerCharacter = character
local function spawnPart()
local part = Instance.new("Part")
part.Parent = workspace.Holder
-- try to print playerCharacter here check if its nil or not
print(playerCharacter.HumanoidRootPart.Position.Y)
part.Position = Vector3.new(math.random(-spawnRadius, spawnRadius), math.random(playerCharacter.HumanoidRootPart.Position.Y + spawnRadius, spawnRadius), math.random(-spawnRadius, spawnRadius))
spawnRadiusObject.Size = Vector3.new(spawnRadius*2, spawnRadiusObject.Size.Y, spawnRadius*2)
workspace.Baseplate.Size = Vector3.new(spawnRadius*2, workspace.Baseplate.Size.Y, spawnRadius*2)
end
for i = 0, 10, 1 do
spawnPart()
task.wait(1)
print("Spawning: "..i)
end
end)
end)
and here’s the line producing the error:
part.Position = Vector3.new(math.random(-spawnRadius, spawnRadius), math.random(playerCharacter.HumanoidRootPart.Position.Y + spawnRadius, spawnRadius), math.random(-spawnRadius, spawnRadius))