Hi, I'm searching for help.... so I am making a zombie game , and I've added some bonus.... but there is a bonus that called "bomb" , if the bomb is touched then he will kill the zombies and give the money, but we don't earn money randomely , for exemple 1 zombie killed will earn us 10 so if 2 zombie are killed by the bomb the player will earn 20, if 20 zombie are dead you will earn 200
So, what I understand is that you want to make a part that kills all zombies when it is touched. That should also reward you 10 Money per zombie.
That is how I would do that: (Please keep in mind that I did not test this, so errors may occure.)
Script in the Part that should be touched:
local part = script.Parent local earning part.Touched:Connect(function(touch) if touch:IsA("Part") or touch:IsA("MeshPart") then if touch.Parent.Humanoid then for i, zombie in ipairs(workspace.Zombies:GetChildren()) do zombie.Humanoid.Health = 0 earning = earning + 10 end print(earning) --This is to test if it is how you want it. game.Players:FindFirstChild(touch.Parent.Name).leaderstats.Money = game.Players:FindFirstChild(touch.Parent.Name).leaderstats.Money + earning --If you dont use leaderstats, change it how you want. end end )
Keep in mind when using this:
1. Every zombie must be in a Folder called "Zombies" found in workspace. (To spawn a zombie like that simply attach
zombie.Parent = workspace.Zombies
into your script)
2. If the script gets a timeout, try to add a wait() to:
for i, zombie in ipairs(workspace.Zombies:GetChildren()) do zombie.Humanoid.Health = 0 earning = earning + 10 end
So, I taked back your script and edited a bit but when I touched the part, it didn't do anything and I got this error (in output):
Zombie is not a valid member of Part
local part = script.Parent local earning part.Touched:Connect(function(touch) if touch:IsA("Part") or touch:IsA("MeshPart") then if touch.Parent.Humanoid then for i, Zombie in ipairs(workspace.Map.Greenrun.spawner.Zombie.Zombie:GetChildren()) do Zombie.Zombie.Health = 0 earning = earning + 10 end print("earning") --This is to test if it is how you want it. game.Players:FindFirstChild(touch.Parent.Name).leaderstats.Argent = game.Players:FindFirstChild(touch.Parent.Name).leaderstats.Argent + earning --If you dont use leaderstats, change it how you want. end end end )
ps: My zombies are not in a folder but a part, and they spawn in a different path:
there are in
Workspace / map (it's a folder) / Greenrun (it's a part group) / spawner (it's the part who the zombie will spawn inside)