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
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!