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

How can I make random choose script? aksuhgfioqwnad

Asked by 4 years ago

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

1local ReplicatedStorage = game:GetService("ReplicatedStorage")
2local EventStorage = ReplicatedStorage.EventStorage
3local clothing = {game.ReplicatedStorage.EventStorage.ClothingEvent2:FireServer(),game.ReplicatedStorage.EventStorage.ClothingEvent1:FireServer()}
4 
5script.Parent.MouseButton1Click:connect(function()
6    game.ReplicatedStorage.EventStorage = clothing[math.random(1, 2)]
7end)
0
make a table Nozyfo 2 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

Hey there. Here is the solution to your problem. Hope it helps! :)

01-- Assignments like you described, no need to change anything here.
02local ReplicatedStorage = game:GetService("ReplicatedStorage")
03local EventStorage = ReplicatedStorage.EventStorage
04-- Event Referencing
05local 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
08local function ChooseRandomCloth()
09    clothing[math.random(1, 2]:FireServer() -- Chooses random event and fires it.
10end
11 
12script.Parent.MouseButton1Click:Connect(ChooseRandomCloth)
0
Works! Thank you so much and sorry for 5 days late. ThadonROOX 47 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

You cannot fire Remotes from a table. You should only fire it when it has been selected from math.random.

Answer this question