Hello Developers! Im making a Zombie Rush type game that spawns zombies however I want to give rewards to players who have survived that round. However my script which has the players in a round is different from the script which spanws the zombies and handles the waves.
So how can I make one of my scripts give rewards to players that are still in the match after a wave has been completed?
Here is my script which handles the players in the round:
And here is my script which handles the waves and spawns zombies:
If anyone can help me it will be highly appreciated!
Maybe you can try making a table for survivors. put all of the players in it when round starts and remove the players that die. Reward everyone in the table when round finishes
Have you read the player script? It already makes a table but how can I make the script which handles the waves know which players to reward and which not?
Not a remote event you have to use a bindable event but. How can I implement this into my script without breaking it. Ive tried using events but I havent put them in the right place so it breaks the script. Do you know what the right place to put is?
-- Define variables
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local MapsFolder = ServerStorage:WaitForChild("Maps")
local Status = ReplicatedStorage:WaitForChild("Status")
local GameLength = 360
local reward = 1
local cash = math.random(1200,3000)
local event = game.ReplicatedStorage.Event
-- Game loop
while true do
Status.Value = "Waiting for enough players to start"
repeat wait() until game.Players.NumPlayers >= 2
Status.Value = "Intermission"
wait(20)
local plrs = {}
for i, player in pairs(game.Players:GetPlayers()) do
if player then
table.insert(plrs,player) -- Add each player into plrs table
end
end
local AvailableMaps = MapsFolder:GetChildren()
local ChosenMap = AvailableMaps[math.random(1,#AvailableMaps)]
Status.Value = ChosenMap.Name.." is the chosen Map"
local ClonedMap = ChosenMap:Clone()
ClonedMap.Parent = workspace
-- Teleport players to the map
Status.Value = "Preparing Arena"
wait (5)
local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")
if not SpawnPoints then
print("Spawnpoints not found!")
end
local AvailableSpawnPoints = SpawnPoints:GetChildren()
for i, player in pairs(plrs) do
if player then
character = player.Character
if character then
-- Teleport them
character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame + Vector3.new(0,10,0)
table.remove(AvailableSpawnPoints,1)
-- Give them a sword and a revolver
local equipped = game.ServerStorage.PlayerData[player.Name].Equipped
if equipped.Value ~= "" then
local weapon = game.ServerStorage.Items[equipped.Value]:Clone()
weapon.Parent = player.Backpack
else
local Knife = ServerStorage.Pistol:Clone()
Knife.Parent = player:WaitForChild("Backpack")
end
local GameTag = Instance.new("BoolValue")
GameTag.Name = "GameTag"
GameTag.Parent = player.Character
else
-- There is no character
if not player then
table.remove(plrs,i)
end
end
end
end
event:Fire()
print ("EventFired")
for i = GameLength,0,-1 do
for x, player in pairs(plrs) do
if player then
character = player.Character
if not character then
-- Left the game
table.remove(plrs,x)
else
if character:FindFirstChild("GameTag") then
-- They are still alive
print(player.Name.." is still in the game!")
else
-- They are dead
table.remove(plrs,x)
print(player.Name.." has been removed!")
end
end
else
table.remove(plrs,x)
print(player.Name.." has been removed!")
end
end
Status.Value = "There are "..i.." seconds remaining, and "..#plrs.." players left"
if #plrs == 0 then
Status.Value = "Monsters have defeated you!"
end
wait(1)
end
print("End of game")
wait(2)
for i, player in pairs(game.Players:GetPlayers()) do
character = player.Character
if not character then
-- Ignore them
else
if character:FindFirstChild("GameTag") then
character.GameTag:Destroy()
end
for _, tool in pairs(player.Backpack:GetChildren()) do
if tool:FindFirstChild("Price") then
tool:Destroy()
end
end
for _, tool in pairs(character:GetChildren()) do
if tool:FindFirstChild("Price") then
tool:Destroy()
end
end
end
player:LoadCharacter()
end
ClonedMap:Destroy()
Status.Value = "Game ended"
wait(2)
end