Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Some help with a non-working block touch death script?

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?

2 answers

✓ Accepted answer

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 :)

7 comments

0

Err, doesn't look that accurate...

0

It doesnt look accurate but it works. Trust me

0

Hungry why dont you check out my games and realize that im a far better scripter than you. Maybe you shouldnt judge a book by its cover :/

0

Woah shots fired

0

^ shots fired indeed xD

0

I've edited mine you know

0

I still feel like my chunk of code is less lines than all of yours and works great. You should use mine :)

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

2 comments

0

Nope, that won't work either.

0

Edited

This discussion is preserved as it was. New answers, comments, and votes are closed.