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

How do I make this script change the text of a gui when the player dies?

Info: Script is a localscript. Script is in StarterPack. Gui is in PlayerGui. ]] Guys I need help. This script is supposed to make the texto of a TextLabel change when a player dies.

local player = game.Players.LocalPlayer
local humanoid = player.Character:FindFirstChild("Humanoid")
local text = player.PlayerGui:WaitForChild("DeathGui").Background.Bar.DeathMessage
local messages ={"You did your best!","Wait, whaat!?","It's ok!","You can't do better?","Don't give up!"}

function changemessage()
	for i = 1,1 do
	for i,v in pairs(messages)do
		end	
	local m = math.random(1,5)
	print(m)
	local text1 = messages[m]
	text.Text = text1
	print(messages[m])
	end
end

player.Character:FindFirstChild("Humanoid").Died:connect(function()
	player.PlayerGui.DeathGui.Background.Visible = true
	wait(.3)
	player.PlayerGui.DeathGui.Background.Bar:TweenSize(UDim2.new(0,800,0,200),"In","Linear",.1)
	wait(.1)
	changemessage()
	player.PlayerGui.DeathGui.Background.Bar.DeathMessage.Visible = true
	script.Fail:Play()
end)

It Works once the player dies but the second time the player dies it won't change.. I don't know why. Anyone willing to help for some rep? I'd really apreciate it :C!

3 comments

0

Hi! I wasn't online so I couldn't answer you, but I see someone yet did. Luck with your game!

0

change it to appear when humanoid health is equal to 0?

0

Didn't work aim.. Can you help me?

1 answer

I have two things to say:

  • One, you don't have codes that removes the GUI and text off the screen, so I suggest you do something like:

player.PlayerGui.DeathGui.Background.Visible = false

and/or

player.PlayerGui.DeathGui.Background.Bar.DeathMessage.Visible = false;

  • Two, You don't need for i = 1,1 do for i,v in pairs(messages)do if you are going to do local m = math.random(1,5) and local text1 = messages[m]

I would just leave it like:

function changemessage()
    local m = math.random(1,5)
    print(m)
    local text.Text = messages[m]
    print(messages[m])
end

or

function changemessage()
    local text.Text = messages[math.random(1,5)]
    print(messages[m])
end

4 comments

0

change math.random(1,5) to math.random(1,#messages)

0

I'll try. Ty

0

Didn't work anyways :(!

0

Nvm I fixed it using your method

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