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

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)
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! :)

-- 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)
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