The numbervalue is always on 0 when player died (serverscriptservice) (SOLVED)

Hello everyone :smiley:, 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 :frowning_face: :tired_face: :sob: 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)
1 Like

There is the print :
image

Player life before die :
image

Player life after died :
image

Print after player died :
image

(The value is a numbervalue)

Can you post the script that changes the players Lifes?

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

The 2 scripts are Localscript and not script in serverscriptservice

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.

1 Like

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”

You can get the player from StarterCharacterScripts using something along the lines of

local character = script.Parent
local player = game:GetService("Players"):GetPlayerFromCharacter(character)

PlayerFromCharacter documentation

1 Like

I tried something but not working again :

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)

Wait i’m dumb, i tried without losing my 3 lives, wait…

OK it’s work, thank you very much, i was demotivated. Thank you ! Your are the best ! :grin:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.