Hi! I'm making script which gonna wear player which clicked textbutton and I want it make randomly, I mean to choose randomly clothes and I made this. What is exactly wrong?
This is this script
1 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
2 | local EventStorage = ReplicatedStorage.EventStorage |
3 | local clothing = { game.ReplicatedStorage.EventStorage.ClothingEvent 2 :FireServer(),game.ReplicatedStorage.EventStorage.ClothingEvent 1 :FireServer() } |
4 |
5 | script.Parent.MouseButton 1 Click:connect( function () |
6 | game.ReplicatedStorage.EventStorage = clothing [ math.random( 1 , 2 ) ] |
7 | end ) |
Hey there. Here is the solution to your problem. Hope it helps! :)
01 | -- Assignments like you described, no need to change anything here. |
02 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
03 | local EventStorage = ReplicatedStorage.EventStorage |
04 | -- Event Referencing |
05 | local clothing { ReplicatedStorage.EventStorage.ClothingEventA, ReplicatedStorage.EventStorage.ClothingEventB } -- Use the service instead of game.ReplicatedStorage and remove integars from the names of the events |
06 |
07 | -- The function itself |
08 | local function ChooseRandomCloth() |
09 | clothing [ math.random( 1 , 2 ] :FireServer() -- Chooses random event and fires it. |
10 | end |
11 |
12 | script.Parent.MouseButton 1 Click:Connect(ChooseRandomCloth) |
You cannot fire Remotes from a table. You should only fire it when it has been selected from math.random.