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

How could i make a if brick touched then kill the zombie and give the money ?

Asked by 5 years ago

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

2 answers

Log in to vote
0
Answered by
DogeIXX 172
5 years ago

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
0
could you check my last thing please I do another script, but it doesn't worked to inconue88 3 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)

0
Does it crash if there is no Zombie in the Spawner? DogeIXX 172 — 5y
0
no it didn't but wait a sec I will change it again... inconue88 3 — 5y
0
here it is the new script inconue88 3 — 5y

Answer this question