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

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

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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.

Ad

Answer this question