Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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!

0
Hi! I wasn't online so I couldn't answer you, but I see someone yet did. Luck with your game! Aimarekin 345 — 6y
0
change it to appear when humanoid health is equal to 0? skillfulzombie88 28 — 6y
0
Didn't work aim.. Can you help me? wilsonsilva007 373 — 6y

1 answer

Log in to vote
0
Answered by
thesit123 509 Moderation Voter
6 years ago

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
0
change math.random(1,5) to math.random(1,#messages) uhTeddy 101 — 6y
0
I'll try. Ty wilsonsilva007 373 — 6y
0
Didn't work anyways :(! wilsonsilva007 373 — 6y
0
Nvm I fixed it using your method wilsonsilva007 373 — 6y
Ad

Answer this question