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

Can someone help me make a randomly talking ragdoll?

Asked by
Stea_my 48
6 years ago

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
0
You need to randomize the line used when chatting. Rheines 661 — 6y
0
use tables - local lines = {"line1","line2","line3","line4","line5"} LoganboyInCO 150 — 6y

1 answer

Log in to vote
0
Answered by
starmaq 1290 Moderation Voter
6 years ago

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!

0
shouldn't the math.random() in line 5 be in the 0,4 range? tables start at 0 DeceptiveCaster 3761 — 6y
0
exactly the same answer i said (but in comment form) LoganboyInCO 150 — 6y
0
It worked, thanks! I'm a newbie scripter so this kind of stuff is unheard of, but practice makes perfect! Thanks!! Stea_my 48 — 6y
0
np! starmaq 1290 — 6y
View all comments (4 more)
0
@MCAndRobloxUnited tables start at 0???? starmaq 1290 — 6y
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. Stea_my 48 — 6y
0
xd starmaq 1290 — 6y
0
Also the game I used yer script at was called "Space" if you wanna check it out! Stea_my 48 — 6y
Ad

Answer this question