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

Can someone help me make a randomly talking ragdoll?

Okay so I'm trying to create a ragdoll that talks randomly, but it dosen't want to work for some dumb reason, it also puts out the error "Unable to cast string to token". Heres my code:

local num1 = 0.5
local num2 = 5
local line1 = "Why me!?!?!?!"
local line2 = "This thing's tounge feels weird!!"
local line3 = "WHY COULDN'T HAVE I BEEN A DOCTOR?!!?!?!?!?"
local line4 = "MY RIBS ARE IN MY EYES!! MY EYES!!!!"
local line5 = "I can't escape!!!"
while true do
math.random(num1,num2)
wait(math.random(num1,num2))
game:GetService("Chat"):Chat(script.Parent.Head, line1,line2,line3,line4,line5,  Enum.ChatColor.Blue)
end

2 comments

0

You need to randomize the line used when chatting.

0

use tables - local lines = {"line1","line2","line3","line4","line5"}

1 answer

✓ Accepted answer

You gotta use tables in ocasions like these, cuz it makes stuff much easier. And in case you don't know how to work with them, here!

So now, if you want to randomize what he's going to say each time it loops, you gotta do table[i] that's gonna represnt each element by its index, so after you put all your lines in a table, let's say the first one is "Why me!?!?!?!", if thats the first member of your table, if you print(table[1]), one is the index of the first element, cuz its the first, i hope you got this idea cuz now you can pretty much do another math.random(), and are 2 arguments are gonna be 1, 5 since we have 5 lines to choose from.

local lines = {"Why me!?!?!?!", "This thing's tounge feels weird!!", "WHY COULDN'T HAVE I BEEN A DOCTOR?!!?!?!?!?", "MY RIBS ARE IN MY EYES!! MY EYES!!!!", "I can't escape!!!"}

while true do
	wait(math.random(0.5, 5))
	game:GetService("Chat"):Chat(script.Parent.Head, lines[math.random(1, 5)]				 
	Enum.ChatColor.Blue)
end

And that should be it, always use tables they are helpful, also your scropt had a lot of uneeded stuff like why did you generate a random number with no use at the start of the loop, and i dont see a why you need to store the math.random arguments 0.5 and 5 in a var.

Happy to help!

8 comments

0

shouldn't the math.random() in line 5 be in the 0,4 range? tables start at 0

0

exactly the same answer i said (but in comment form)

0

It worked, thanks! I'm a newbie scripter so this kind of stuff is unheard of, but practice makes perfect! Thanks!!

0

np!

0

@MCAndRobloxUnited tables start at 0????

0

Also, nice catch with the random number generator! I didn't even think I did, must've did it without realizing when trying to make the random wait time.

0

xd

0

Also the game I used yer script at was called "Space" if you wanna check it out!

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