Can I get some help? I'm a new programmer and I'm making a game and everything went well until this:
function MakeABall() wait(5) local bally = Instance.new("Part") bally.Shape = ("Ball") bally.BottomSurface = ("Smooth") bally.TopSurface = ("Smooth") bally.BrickColor = BrickColor.new("Dark stone grey") bally.Material = ("Slate") bally.Parent = game.Workspace bally.Position = Vector3.new(40,94,-218.5) function onTouch(part) local humanoid = part.Parent:FindFirstChild("Humanoid") if (humanoid ~= nil) then humanoid.Health = 0 end bally.Touched:connect(onTouch) end end while true do MakeABall() end
I need a ball to spawn every 5 seconds, then if the player touches the ball they will die, and while the ball is spawning in the correct space every 5 seconds like it should, the ball won't kill the player on touch. Some help please?
Here is what I would do:
while wait(5) do bally = Instance.new("Part") bally.Name = "Bally" bally.Shape = ("Ball") bally.BottomSurface = ("Smooth") bally.TopSurface = ("Smooth") bally.BrickColor = BrickColor.new("Dark stone grey") bally.Material = ("Slate") bally.Parent = game.Workspace bally.Position = Vector3.new(40,94,-218.5) bally.Touched:connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid ~= nil then hit.Parent.Humanoid.Health = 0 end end) end
It works but i didn't do it the way you did. But it works :)
Whatevs. Guess I was wrong about the whole infinite loop thing crashing the game.
function MakeABall() local bally = Instance.new("Part") bally.Shape = ("Ball") bally.BottomSurface = ("Smooth") bally.TopSurface = ("Smooth") bally.BrickColor = BrickColor.new("Dark stone grey") bally.Material = ("Slate") bally.Parent = workspace bally.Position = Vector3.new(40, 94, -218.5) local function onTouch(part) local humanoid = part.Parent:FindFirstChild("Humanoid") if (humanoid ~= nil) then humanoid.Health = 0 end end wait(5) --Wait 5 seconds to connect the onTouch function bally.Touched:connect(onTouch) end while true do MakeABall() end