Hello everyone, i make my new game with a intermission and game system (i create it) but it don’t work correctly with lifes system. When the player died, he lost 1 life (The player have 3 life in the round). The round is finished if everyone is dead with 0 life left, but when my player died, the game is finished and go to intermission when my player have only 2 lifes lefts … I need help, tried everything like using the playerscriptservice, characterscriptservice, serverscriptservice.
This is the script in serverscriptservice for the round lifes system :
local PlayersService = game:GetService("Players")
PlayersService.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function()
plr.Character:WaitForChild("Humanoid").Died:Connect(function()
if plr.Playing.Value == true and plr.Lifes.Value < 1 then
print("!!!DEAD!!!")
game.ReplicatedStorage.AlivesPlayers.Value += -1
end
end)
end)
end)
This is the script that give 3 lifes for everyone when the round is starting :
local Player = game.Players.LocalPlayer
local Event = game.ReplicatedStorage.GivingLifes
Event.OnClientEvent:Connect(function()
Player.Lifes.Value = 3
end)
This is a part of the script that remove 1 life when the player die :
if Player.Lifes.Value > 0 then
Player.Playing.Value = true
Player.Lifes.Value += -1
game.ReplicatedStorage.Died:FireServer()
else
Player.Playing.Value = false
game.ReplicatedStorage.Died:FireServer()
end
Why do you need to remove/add the player’s lives on the client side? If you add a ServerScript into StarterCharacterScripts, that’ll handle all of this whilst still being serversided, and have nothing to do with remote events.
What script can i do ? I don’t know how to have the player in serverscriptservice ? Because i have directly the player in localscript with “game.Players.LocalPlayer”
local character = script.Parent
local player = game:GetService("Players"):GetPlayerFromCharacter(character)
local WasPlaying
local Event = game.ReplicatedStorage.GivingLifes.OnServerEvent
character:WaitForChild("Humanoid").Died:Connect(function()
WasPlaying = player.Playing.Value
if WasPlaying == true then
if player.Lifes.Value > 0 then
player.Playing.Value = true
player.Lifes.Value += -1
else
player.Playing.Value = false
game.ReplicatedStorage.AlivesPlayers.Value += -1
end
end
end)