Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make random choose script? aksuhgfioqwnad

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

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EventStorage = ReplicatedStorage.EventStorage
local clothing = {game.ReplicatedStorage.EventStorage.ClothingEvent2:FireServer(),game.ReplicatedStorage.EventStorage.ClothingEvent1:FireServer()}

script.Parent.MouseButton1Click:connect(function()
    game.ReplicatedStorage.EventStorage = clothing[math.random(1, 2)]
end)

1 comment

0

make a table

2 answers

✓ Accepted answer

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

-- Assignments like you described, no need to change anything here.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EventStorage = ReplicatedStorage.EventStorage
-- Event Referencing
local clothing {ReplicatedStorage.EventStorage.ClothingEventA, ReplicatedStorage.EventStorage.ClothingEventB} -- Use the service instead of game.ReplicatedStorage and remove integars from the names of the events

-- The function itself
local function ChooseRandomCloth()
	clothing[math.random(1, 2]:FireServer() -- Chooses random event and fires it.
end

script.Parent.MouseButton1Click:Connect(ChooseRandomCloth)

1 comment

0

Works! Thank you so much and sorry for 5 days late.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.