Making a new post so people can respond to my problem that it’s not yet solved unfortunately…
Thanks for reading.
Making a new post so people can respond to my problem that it’s not yet solved unfortunately…
Thanks for reading.
To continue off of where your last post has left off, simply use a for loop in order to find the player/players who are still alive in the game. I’ve done this before using a table for current players but it is more than acceptable to do with teams. Just do something like:
local winners = {}
local players = game.Players:GetChildren()
for i,v in pairs(players) do
if v.Team == "Your Team Here" then
table.insert(winners, v)
end
end
Then you will have a table containing your winners. I don’t use teams very often so I’m sure that there is probably a different way to go about this but this should definitely work.
You also don’t provide how you’re putting players into the table (or atleast I didn’t see it)
I would try using:
table.remove(plrs, table.find(plrs, player) )
I put players into the table by simply doing this script:
local plrs = {}
for i, player in pairs(game.Players:GetPlayers()) do
if player then
table.insert(plrs,player) -- Adds Players in the table
end
end
Additionally, I’ve already tried that method previously but instead of saying someone won it now says that nobody won
then its locating and removing properly
are you sure its not an issue with how you handling whether or not when to remove someone from the table i.e. your logic? can you answer when should a player get removed?
I also done the same script as you did for adding the players into a table.
My game has a life system. Whenever you die you lose a life but you are still in the game, thus won’t get removed in the “plrs” list. However, if you die and your lives is on 0 then you get removed from the table.
Each player gets three lives
the issue is dependent on a code base not visible to us, you’ll need to solve the issue on your own or provide the logic behind the lives system and how its being handled, need to show whats going on at the end of match code as well.
i would also suggest debugging with prints since you’ll be able to see whats happening on your end.
Ah ok, I’m trying to debug it right now but just in case I might as well send the code to you.
Lives System:
local script
Humanoid.Died:Connect(function()
if LivesCount.Value ~= 1 then
if gameStarts.Value == true then
LivesCount.Value -= 1
game:GetService("ReplicatedStorage"):WaitForChild("NotDead"):FireServer()
end
else
print("dead")
LivesCount.Value -= 1
game:GetService("ReplicatedStorage"):WaitForChild("ActuallyDead"):FireServer()
end
end)
server script
player.CharacterAdded:Connect(function(character)
character.Humanoid.WalkSpeed = 16
character.Humanoid.Died:Connect(function()
-- Whenever somebody dies, this event will runs
game:GetService("ReplicatedStorage"):WaitForChild("NotDead").OnServerEvent:Connect(function()
if player then
if GamesStart.Value == true then
wait(5)
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 sword = game.ServerStorage.ClassicSword:Clone()
sword.Parent = player.Backpack
end
local tag = game.ReplicatedStorage:WaitForChild("tag")
local spawnPointsSecond = workspace:WaitForChild(tag.Value):FindFirstChild("SpawnLife")
local character = player.Character
if character then
if spawnPointsSecond:IsA("Part") then
character:FindFirstChild("HumanoidRootPart").CFrame = spawnPointsSecond.CFrame
end
end
end
end
end)
game:GetService("ReplicatedStorage"):WaitForChild("ActuallyDead").OnServerEvent:Connect(function()
if GamesStart.Value == true then
if character:FindFirstChild("GameTag") then
character.GameTag:Destroy()
end
player.Team = game.Teams["Not Playing"]
wait(2)
game.ReplicatedStorage:WaitForChild("SpectateShow"):FireClient(player, true)
game.ReplicatedStorage:WaitForChild("EquippedShow"):FireClient(player, true)
game.ReplicatedStorage:WaitForChild("Lives"):FireClient(player, false)
game.ReplicatedStorage:WaitForChild("LivesButThisTimeItWillWok"):FireClient(player)
end
end)
end)
end)
Local script:
game:GetService("ReplicatedStorage"):WaitForChild("LivesButThisTimeItWillWok").OnClientEvent:Connect(function(player)
game:GetService("ReplicatedStorage"):WaitForChild("tablePlrs"):FireServer(player)
print("adkjf;alksdfja;sldkf") -- debugging purposes haha
end)
Server script
game:GetService("ReplicatedStorage").tablePlrs.OnServerEvent:Connect(function(player)
table.remove(plrs, table.find(plrs, player))
end)
End of match:
if #plrs == 1 then
-- Victory Royale
GameYes = false
Status.Value = "The winner is "..plrs[1].Name
if plrs[1]:FindFirstChild("X5").Value == true and plrs[1]:FindFirstChild("X2").Value == true then
plrs[1].leaderstats.Shards.Value = plrs[1].leaderstats.Shards.Value + reward * 7
elseif plrs[1]:FindFirstChild("X5").Value == false and plrs[1]:FindFirstChild("X2").Value == true then
plrs[1].leaderstats.Shards.Value = plrs[1].leaderstats.Shards.Value + reward * 2
elseif plrs[1]:FindFirstChild("X5").Value == true and plrs[1]:FindFirstChild("X2").Value == false then
plrs[1].leaderstats.Shards.Value = plrs[1].leaderstats.Shards.Value + reward * 5
else
plrs[1].leaderstats.Shards.Value = plrs[1].leaderstats.Shards.Value + reward
end
if plrs[1]:FindFirstChild("Wins5").Value == true then
plrs[1].leaderstats.Wins.Value = plrs[1].leaderstats.Wins.Value + winreward * 5
else
plrs[1].leaderstats.Wins.Value = plrs[1].leaderstats.Wins.Value + winreward
end
break
elseif #plrs == 0 then
GameYes = false
Status.Value = "Somehow NOBODY Won"
break
elseif i == 0 then
GameYes = false
Status.Value = "Times up bozos"
break
end
Some of the codes i written are kinda irrelevant to this topic so just ignore them (like the end of match code, the long written code were just gamepass related stuff).
this is the solution
I noticed you’re not using a player arguement for the function onserverevent,
given that any 1 person will fire the event, all listening connections will hear the event fire and will fetch their own player variable from .PlayerAdded, thus removing any and all players
add a plr variable from OnServerEvent and use that as a condition for your logic
game:GetService("ReplicatedStorage"):WaitForChild("ActuallyDead").OnServerEvent:Connect(function(plr)
if plr ~= player then
--dont do died logic
return
end
the above goes for ALL your .onserverevents double check all of them @SkabaYay
remember whenever a client fireserver, it automatically passes the player who fired.
I have a few questions about this if you don’t mind
what do you mean by adding a plr variable? Do you mean I make a completely new variable or do I use the list that is called plr?
what does it mean by your comment “don’t do died logic?”
sorry about my misunderstanding
at the end of a connection, there are args, in this case we need a player argument called plr as to avoid confusion with the current “player” arguement from .PlayerAdded (or however ur fetching the player earlier)
if plr ~= player then
–dont do died logic
return
end
this code snippet is what is needed for your “ActuallyDead” to work without table.removing all players (through communications), after adding in the plr arg, I put a comment explaining the purpose, if the receiving plr arguement is not == to the player that we are listening for then return and dont do died logic for them since its not our target player
hm, seems like it doesn’t work for me; I’m I missing something?
game:GetService("ReplicatedStorage"):WaitForChild("ActuallyDead").OnServerEvent:Connect(function(plr)
if plr ~= player then
return
end
if GamesStart.Value == true then
if character:FindFirstChild("GameTag") then
character.GameTag:Destroy()
end
player.Team = game.Teams["Not Playing"]
wait(2)
game.ReplicatedStorage:WaitForChild("SpectateShow"):FireClient(player, true)
game.ReplicatedStorage:WaitForChild("EquippedShow"):FireClient(player, true)
game.ReplicatedStorage:WaitForChild("Lives"):FireClient(player, false)
game.ReplicatedStorage:WaitForChild("LivesButThisTimeItWillWok"):FireClient(player)
end
end)
You can try this method.
local tables = {"lol", "yeah"}
table.remove(tables, table.find(tables, "lol"))
print(tables) -- only prints yeah
Add it to the “NotDead” one too,
also spotted another issue, you have the connections nested within .Died, I would remove them out of .Died function & the .characteradded function…
I did that, but the problem is still not solved
Also, when i put the if plrs ~= players in the code that actually removes the player from the list the game would still carry on
… my code is a mess
In the nicest way possible, I think you should consider refactoring the majority of your code.
Even with your description of what your code is supposed to be doing it’s very hard to figure out what’s going on contextually. You don’t have to necessarily remake all your scripts, but take what works and take the responses you’ve received here to help achieve your desired life system.