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

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

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

Try this

for i,v in pairs(game:GetService("Players"):GetDescendants()) do
	if v.Name = currencyname then
		v.Value += amountofcurrency
	end
end

3 comments

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

0

Instead of :GetDescendants use :GetPlayers() and do :FindFirstChild("Currencyname",true).Value += amountofcurrency

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

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