Ad
Log in to vote
1

How do I make everyone gain money when a enemy dies?

Asked by 21 days ago

Hey there I'm working on a basic zombie defense game and I want to make it to when a zombie dies every player in the game gains money. I already have leaderstats and a currency set up I just don't know how to add x amount of currency to everyone's balance when a zombie dies.

If your curious why everyone and not the person who killed the zombie

I'm doing everyone gets money when a zombie dies because the bullets are made of parts so its difficult to give the player who killed the zombie the money.

1 answer

Log in to vote
0
Answered by
NykoVania 198 Moderation Voter
21 days ago

Try this

for i,v in pairs(game:GetService("Players"):GetDescendants()) do
    if v.Name = currencyname then
        v.Value += amountofcurrency
    end
end
0
hmm I'm still having issues I had to switch some things up because of errors I had to change the GetDescendants cause stuido didint like that. im getting error on line 10 about trying to intex Nil with WaitForChild but I dont see the issue. the code hassint worked though this is what I got --> local Zombie = script.Parent:WaitForChild("Zombie") Zombie.Died:connect(function() local Players = ga xxXDuckzzXxx 15 — 21d
0
Instead of :GetDescendants use :GetPlayers() and do :FindFirstChild("Currencyname",true).Value += amountofcurrency NykoVania 198 — 21d
0
hmm I dont think its possible because you have to find a localplayer to find leaderstats. thank you for trying to help its very much appreciated! I have a ghetto solution in mind. I hope your havin a great day, night :) xxXDuckzzXxx 15 — 21d
Ad

Answer this question