Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

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

Asked by
Scootakip 299 Moderation Voter
8 years ago

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

Log in to vote
-1
Answered by 8 years ago

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

0
Err, doesn't look that accurate... HungryJaffer 1246 — 8y
0
It doesnt look accurate but it works. Trust me Alucifer 45 — 8y
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 :/ Alucifer 45 — 8y
0
Woah shots fired Scootakip 299 — 8y
View all comments (3 more)
0
^ shots fired indeed xD Alucifer 45 — 8y
0
I've edited mine you know funyun 958 — 8y
0
I still feel like my chunk of code is less lines than all of yours and works great. You should use mine :) Alucifer 45 — 8y
Ad
Log in to vote
-1
Answered by
funyun 958 Moderation Voter
8 years ago

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
0
Nope, that won't work either. Scootakip 299 — 8y
0
Edited funyun 958 — 8y

Answer this question