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

Script not giving a character a random face as it is supposed to?

Asked by
CodeWon 181
3 years ago

This script is supposed to give the npc I made a random face from a table of face id's. I know the problem but how can I get it to show the value of the random face instead of the index?

local faces = {22877700, 255827175, 8560971, 10907551, 209994929}

local randomFace = math.random(1,#faces)

script.Parent:WaitForChild("Head").face.Texture = "rbxassetid://"..randomFace

1 answer

Log in to vote
0
Answered by 3 years ago

Just change line 3 to:

local faces = {22877700, 255827175, 8560971, 10907551, 209994929}

local randomFace = faces[math.random(1,#faces)]

script.Parent:WaitForChild("Head").face.Texture = "rbxassetid://"..randomFace

In your script, you are saying that randomFace = a random number from 1 - 5, which is not what you want. But in the revised script, it is getting a random 1 - 5 from the table faces (ex. faces[1], faces[2], etc etc.) You can also do;

local faces = {22877700, 255827175, 8560971, 10907551, 209994929}

local randomFace = math.random(1,#faces)

script.Parent:WaitForChild("Head").face.Texture = "rbxassetid://"..faces[randomFace]

Hope this helps

Ad

Answer this question