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

How do you loop and normal script, and how can I fix this?

It's a normal script within serverscriptservice. "RealMoney" is the name of my currency and isn't in a leaderboard. "Zombie" is the name of the model which is a zombie and inside zombie I named the humanoid to zombie. "boost" is the boost you get from pets. This only works once, for example when I kill 1 zombie it works then when I go to kill another it doesn't work.

game:GetService('Players').PlayerAdded:Connect(function(player)
        player.CharacterAdded:Connect(function(character)
local RealMoney = player:FindFirstChild("RealMoney")
local boost = player:FindFirstChild("CoinBoost")
local Zombie = game.Workspace.Zombie


            Zombie:WaitForChild("Zombie").Died:Connect(function()
                player.RealMoney.Value = player.RealMoney.Value + 1000 + boost.Value
            end)
        end)
    end)

1 answer

✓ Accepted answer

It's because when you define 'local Zombie', you've defined just one of the zombies that you have, not all of them, thus the event only works once.. The only way I can think of from the top of my head is naming each zombie with a number ie 'Zombie1', 'Zombie2' etc so that the event will trigger when a specific zombie is killed.

If this doesn't work, try putting your 'zombie killed' event outside of the PlayerAdded event - you've wrapped it in the PlayerAdded event by putting the 'end's at the bottom of the script, not one before the start of the zombie killed event. This means that The zombie killed event and the PlayerAdded event look like they are one function and so can't happen again. A solution would just be to put an end after the PlayerAdded function and all variables are defined.

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