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

How to spawn npc with random clothing ?

Asked by 3 years ago

Hello, a few weeks ago I got stuck on my code, the code only works if you put an id, except if you add 2 or more id the code when the npc appears becomes null..

shirts = {
    1118202405, 
    1537761670, 
    1442388484, 
    4413177915, 
    1471488077, 
    751482380, 
    2403967461

}

    local randomshirt = math.random(7,#shirts)
    local clothing = script.Parent.Clothing

clothing.ShirtTemplate = "rbxassetid://"..shirts[randomshirt]

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

The only problem that I can see is that you're using math.random incorrectly (at least in this use case). math.random has two arguments; the minimum value and the maximum value. In this case you'd want the minimum value to be 1, not 7.

I'd also suggest setting the randomseed to get more random values. The most convenient way to truly randomize the seed is to just set it to tick(), which is a function that returns the time passed in Roblox's servers.

math.randomseed(tick())
shirts = {
    1118202405, 
    1537761670, 
    1442388484, 
    4413177915, 
    1471488077, 
    751482380, 
    2403967461

}

    local randomshirt = math.random(1,#shirts)
    local clothing = script.Parent.Clothing

clothing.ShirtTemplate = "rbxassetid://"..shirts[randomshirt]

0
it works, except that the npc all have the same id put in ShirtTemplate, except that the game refuses to display them in the npc directly, the data is well put, but no display update is done on the npc. Maxime66410 14 — 3y
0
Same problem. I test with 3 option. [https://i.gyazo.com/02a3a7d41f0006b56c013b447278ede8.gif](https://i.gyazo.com/02a3a7d41f0006b56c013b447278ede8.gif) In video : [https://i.gyazo.com/668a0c4e387caf17ebea340dec02cdf6.mp4](https://i.gyazo.com/668a0c4e387caf17ebea340dec02cdf6.mp4) but if I enter it myself by pressing "enter", it works. [https://i.gyazo.com/0f29f65b2fee49cb8ded9cc2c5703697.mp4 Maxime66410 14 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Same problem.

I test with 3 option.

https://i.gyazo.com/02a3a7d41f0006b56c013b447278ede8.gif

In video :

https://i.gyazo.com/668a0c4e387caf17ebea340dec02cdf6.mp4

but if I enter it myself by pressing "enter", it works.

https://i.gyazo.com/0f29f65b2fee49cb8ded9cc2c5703697.mp4

Answer this question