Hey Fellow developers I’m working on a game a there’s a problem with my script first of all the player wont respawn when they die or leave the Plr table 0n death also they player who is the last one standing wont win the game when the game is over.
Can anyone help me fix/improve my code if you need me to explain more just ask
thanks
local Replicatedstorage = game:GetService("ReplicatedStorage")
local Serverstorage = game:GetService(“ServerStorage”)
local MapsFolder = Serverstorage:WaitForChild(“Maps”)
local NeededPlayers = 2
local Status = game.Workspace.Values.Status
local Gamelenght = 60
local IntermissionTime = 10
while true do
Status.Value = “Waiting For Enough Players!”
repeat wait(1) until game.Players.NumPlayers >= NeededPlayers
Status.Value = “Intermission”
wait(IntermissionTime)
local plrs = {}
for i , player in pairs(game.Players:GetPlayers()) do
if player then
table.insert(plrs,player)
end
end
wait(2)
local AvalibleMaps = MapsFolder:GetChildren()
local ChosenMap = AvalibleMaps[math.random(1,#AvalibleMaps)]
local ClonedMap = ChosenMap:Clone()
local Gun = Serverstorage.Gun.Gun
ClonedMap.Parent = game.workspace
Status.Value = ChosenMap.Name.." Map Chosen!"
wait(3)
local Spawnpoints = ClonedMap:FindFirstChild("SpawnPoints")
local AvalibleSpawnPoints = Spawnpoints:GetChildren()
local GunSpawnpoints = ClonedMap:FindFirstChild("GunSpawns")
local Children = GunSpawnpoints:GetChildren()
local ChosenGunSpawn = Children[math.random(1, #Children)]
Gun.CFrame = ChosenGunSpawn.CFrame
Gun.Parent = game.Workspace
function OnTouch(Part)
if Part.Parent ~= nil and Part.Parent:FindFirstChild("Humanoid") then
local RealGun = game.ReplicatedStorage.Weapons.HandGun
local GunClone = RealGun:Clone()
GunClone.Parent = game.Players:findFirstChild(Part.Parent.Name).Backpack
Gun:Destroy()
end
end
for i, player in pairs(plrs) do
if player then
character = player.Character
if character then
character:FindFirstChild("HumanoidRootPart").CFrame = AvalibleSpawnPoints[1].CFrame
table.remove(AvalibleSpawnPoints,1)
local gametag = Instance.new("BoolValue")
gametag.Name = "GameTag"
gametag.Parent = player.Character
else
if not player then
table.remove(plrs,i)
end
end
end
end
Status.Value = "Find The Gun!"
wait(2)
for i = Gamelenght,0,-1 do
Gun.Touched:Connect(OnTouch)
for x, player in pairs(plrs) do
if player then
character = player.character
if not character then
else
if character:FindFirstChild("GameTag") then
else
table.remove(plrs,x)
end
end
else
table.remove(plrs,x)
end
end
Status.Value = i
if #plrs == 1 then
Status.Value = "The Winner Is "..plrs[1].Name.."!"
plrs[1].leaderstats.Cash.Value = plrs[1].leaderstats.Cash.Value + 1
wait(4)
break
elseif i == 0 then
Status.Value = "Times Up"
break
end
wait(1)
end
for i, player in pairs(game.Players:GetPlayers()) do
character = player.character
if not character then
else
if character:FindFirstChild("GameTag") then
character.GameTag:Destroy()
if character:FindFirstChild("HandGun") then
end
character.HandGun:Destroy()
end
if character:FindFirstChild("HandGun") then
character.Gun:Destroy()
end
end
player:LoadCharacter()
end
ClonedMap:Destroy()
Gun:Destroy()
Status.Value = “Game Ended”
end