Help with a +1 death counter script

Hi,

I need some help. Im trying to make a death counter script. So this is on a part and its like a total off counter! So Im not very sure how to add 1 to the value of the text. I know how to make it 0 when the game starts but I don’t know haw to add one to it. Its simple but I don’t know how to do it. Please don’t harsh on me for not knowing. Im just trying to learn a bit more.

from,
File

2 Likes

Are you trying to modify like a textLabel on the part?

this is the script I have so far

script.Parent.Text = "0"

game:GetService('Players').PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
	    character:WaitForChild("Humanoid").Died:Connect(function()
	    script.Parent.Text = (i dont know what goes here) + 1	
	    end)
    end)
end)

yes. That is what I’m trying to do.

yeah its best off to have a separate counter variable thats a number and then go

script.Parent.Text = "Some text "..thatVariable

the two dots concatenate or better yet combine the text and the number. i think it should work though i should test it first

You could put: script.Parent.Text = (script.Parent.Text +1) on this line

thanks! Now I can use this in a lot for scripts.

What you can do is have a variable that changes every death.

script.Parent.Text = "0"

local Deaths = 0

game:GetService('Players').PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
	    character:WaitForChild("Humanoid").Died:Connect(function()
Deaths = Deaths + 1
	    script.Parent.Text = "Deaths: "..Deaths	
	    end)
    end)
end)
1 Like

It wont work, im pretty sure, since the .Text is a string, not a number. Cant operate math stuff

there you go, that’s what im talkin about

Pretty sure it still works if the string only contains numbers, though it if doesnt you could apply this small change
script.Parent.Text = (tonumber(script.Parent.Text)+1)

then in that case yes, but the other method is probably gonna be used more cause u wanna tell the player what the counter is for