I have a sort of Natural Disaster Game or whatever and I want to pass a variable which holds a random item of a table to a local script.
Server Script:
local serverstorage = game:GetService(“ServerStorage”)
local DisastersFolder = serverstorage:WaitForChild(“Disasters”)
local Disasters = DisastersFolder:GetChildren()
local button = script.Parent
local DisastersInProgress = workspace.Map.DisastersInProgress
local clickdec = script.Parent.ClickDetector
local db = false
clickdec.MouseClick:Connect(function(plr)
if db == false then
local count = #Disasters
db = true
local choiceindex = math.random(1, count)
local choice = Disasters[choiceindex]
print(choice)
game:GetService(“ReplicatedStorage”).DisasterGUI:FireAllClients(choice)
task.wait(5)
choice.Parent = DisastersInProgress
task.wait(10)
choice.Parent = serverstorage
db = false
end
end)
Local Script:
local repstorage = game:GetService(“ReplicatedStorage”)
local StarterGui = game:GetService(“StarterGui”)
local Text = StarterGui.TextGui.DisasterText
local DisasterGui = repstorage.DisasterGUI
you’re sending a number as ‘choice’ so it can’t be set to the text unless you either convert it to text based on the number in the server script, or in the local script and set the text to that.
server script example:
if choice == 1 then
local c = "Tornado"
elseif choice == 2 then
local c = "Tsunami"
game:GetService(“ReplicatedStorage”).DisasterGUI:FireAllClients(c)
when i print choice it prints “Laser” and laser is the only disaster in the folder as im doing the scripting first.
so i dont know why you are saying its a number?
also i made the concatenation to, tostring
uhhhhhhhhhhhh guys wait i think i have solution but probably the most unlikliest; put wait statement on client bcz i think for the client the disasters havent loaded yet so it appears as nil due to the fact Disasters[choiceindex] = nil on the clientside