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

Script is NOT changing the text after player dies. Help?

Guys I have a prob. In this following script I have a math.random function that is called when a player dies, and changes the deathmessage that apears on screen when a player dies. But when the player dies for a second time the script doesn't change the message i don't know why.. Here's the script:

function changemessage()
local messages = math.random(5)
print(messages)
wait(.1)
if messages == 1 then
	text.Text = "You did your best!"
end
if messages == 2 then
	text.Text = "Wait, whaat!?"
end
if messages == 3 then
	text.Text = "It's ok!"
end
if messages == 4 then
	text.Text = "You can't do better?"
end
if messages == 5 then
	text.Text = "Don't give up!"
end
end
--When player dies it calls "changemessage()".

Anyone willing to help for some rep?

1 answer

✓ Accepted answer

You had two mistakes. First, the math random needs a minimum and a maximum. And second, that value needs to be rounded. Otherwise, the math random could return decimals. Here you've got the script corrected:

function changemessage()
local messages = math.floor (math.random(0.1, 4.9)) -- floor gets rounded to its upper non-decimal number, so that's why it's 0.1, 4.9.
print(messages)
wait(.1)
if messages == 1 then
    text.Text = "You did your best!"
end
if messages == 2 then
    text.Text = "Wait, whaat!?"
end
if messages == 3 then
    text.Text = "It's ok!"
end
if messages == 4 then
    text.Text = "You can't do better?"
end
if messages == 5 then
    text.Text = "Don't give up!"
end
end
--When player dies it calls "changemessage()".

Anyway, if you want to add more possible text, just add another if messages == blablabla... and plus 1 to the 4.9 in math.random

EDIT: Should work! Aimarekin. xD

7 comments

0

Ty!

0

No Problem! Tip: Renember math.floor always rounds up! and math.ceil rounds down! Also, math.random can generate decimals!

0

It fixed the choosing things at random but it still wont change the text Idk how.. Any Idea how to fix that? :3

0

Hummm you would need to give me the entire code for that

0

You could post another question

0

All Right. I'll do that.

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