Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

died function/num value problems point out mistakes please?

died function won't work for me its a local script in a screengui trying to get a textlabel's text to change to the player's current lives (player has 20 lives total) i tried using a number value but i dont know much about those so im trying this EDIT: got script 1 to work now im trying a way but ill put both local scripts below

script 1 (Edited)

local lives = script.Parent.Lives.CurrentLives.Value
local textlabel = script.Parent.Lives
	
function onDeath()
print('Someone has died! :0')
lives = (lives - 1)
print(lives)
textlabel.Text = "x"..lives
wait(0)
end
	if textlabel.Text == "x0" then do
		print("Someone has lost all their lives!")
		wait(2)
		textlabel.Text = ("GAME OVER!")
		script.Parent.Frame.Visible = true		
	end	
end
		
game.Players.LocalPlayer.Character.Humanoid.Died:connect(onDeath)

script 2 (new)

game.Players.PlayerAdded:connect(function(Player)
	
local numbvalue = Instance.new('NumberValue')
		numbvalue.Parent = Player
	    numbvalue.Name = 'Lives'
	    numbvalue.Value = 20
	 
	    Player.CharacterAdded:connect(function(Character) 

	        Player.PlayerGui.LivesGui.LivesRemaining.Text = 'x'..numbvalue.Value
	 	
	        Character.Humanoid.Died:connect(function()
	            numbvalue.Value = (numbvalue.Value - 1)
	            Player.PlayerGui.LivesGui.LivesRemaining.Text = 'x'..numbvalue.Value
	            print(Player.Name..' has lost a life and now has '..numbvalue.Value..' left!')
	        end)
	end)
end)

help :(

1 answer

game.Players.PlayerAdded:connect(function(Player)

	Instance.new'NumberValue'.Parent=Player
	Player.Value.Name='Lives'
	Player.Lives.Value=10
	
	Player.CharacterAdded:connect(function(Character)
		
		Player.PlayerGui.ScreenGui.TextLabel.Text='x'..(Player.Lives.Value)
		
		Character.Humanoid.Died:connect(function()
			Player.Lives.Value=Player.Lives.Value-1
			Player.PlayerGui.ScreenGui.TextLabel.Text='x'..(Player.Lives.Value)
			print(Player.Name..' has lost a life and now has '..Player.Lives.Value..' left!')
		end)
	end)
end)

4 comments

0

Died function wont work

0

What does the output say?...

0

Because it works for me

0

Output says nothing

This discussion is preserved as it was. New answers, comments, and votes are closed.