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

Is there another way to store the player as a variable because the script isn't looping?

Asked by 4 years ago

"RealMoney" is the currency and is in the player not in leaderstats "Zombie" is the name of the zombie and I renamed the humanoid into Zombie The script works once, For example when the Zombie dies money is given but when it respawns and I kill it again nothing happens.

local Humanoid = game.Workspace.Zombie

game:GetService('Players').PlayerAdded:Connect(function(player)
        player.CharacterAdded:Connect(function(character)
            Zombie:WaitForChild("Zombie").Died:Connect(function()
                player.RealMoney.Value = player.RealMoney.Value + 1000
            end)
        end)
    end)

1 answer

Log in to vote
2
Answered by
kisty1 111
4 years ago

You'd want to use workspace.ChildAdded so that when new zombies get added, and they die, the player gets money again Keep in mind that this will only work if the zombie gets added to workspace

workspace.ChildAdded:Connect(function(zombie)
    if zombie.Name == "Zombie" then
        zombie:WaitForChild("Zombie"),Died:Connect(function()
            player.RealMoney.Value = player.RealMoney.Value + 1000
        end)
    end
end)
Ad

Answer this question