Okay, so I’m trying to make a system in which you press a button and a random remote event is fired. I already made the table of remote events in Replicated Storage, but they won’t fire for some reason.
Here is an example of the script explained with outdated memes:
(Why in the world did I use these as an example out of everything…)
Script 1 (Location: Normal script within the button)
local button = game.Workspace.Button.Button
local player = game:GetService("Players").LocalPlayer
local RS = game:GetService("ReplicatedStorage")
local Events = RS.RandomEvents:GetChildren()
local IfButtonBusy = game.Workspace.Button.Button.IfButtonIsBusy
IfButtonBusy.Value = false
local function RandomEvent(player)
if IfButtonBusy.Value == false then
button.BrickColor = BrickColor.new("Really red")
print("FUNCTION START!!")
IfButtonBusy.Value = true
local Random = math.random(1, #Events)
local RandomEvent = Events[Random]
RandomEvent:FireClient(player) --Error message
print(RandomEvent.Name.. " was fired.")
wait(10)
IfButtonBusy.Value = false
print("BUTTON RECHARGED!")
button.BrickColor = BrickColor.new("Lime green")
end
end
button.ClickDetector.MouseClick:Connect(RandomEvent)
Script 2 (Location: ServerScriptService) (Don’t really know if I need the player variable but I have it just because)
local player = game:GetService("Players").LocalPlayer
--Folder Variables
local RandomEvents = game.ReplicatedStorage.RandomEvents
--Event Variables
local Event1 = RandomEvents:WaitForChild("Creeper")
local Event2 = RandomEvents:WaitForChild("WidePres")
local Event3 = RandomEvents:WaitForChild("Yankee")
--Creeper function
local function CreeperAwMan()
print("Creeper? Awww man.")
end
--Wide President function
local function WidePresident()
print("lol is this meme dead?")
end
--Yankee w/ no brim function
local function YankeeBrim()
print("YANKEE WITH NO BRIM!!")
end
--Event Connecting
Event1.OnServerEvent:Connect(CreeperAwMan)
Event2.OnServerEvent:Connect(WidePresident)
Event3.OnServerEvent:Connect(YankeeBrim)
Okay I deleted the player variable and its still doing the same thing.
So, to give more insight, the entire function runs, and it prints the functions from the first script. But for some reason the second script’s print statements don’t print, and no errors show up so I have no idea how to fix it. I already tried getting rid of the player between parenthesis (Brought up an error, so I put it back) and switching the client and server parts of the script. (Also brought up an error; not sure why I thought it would work)
Put the Second Script code all in a Local Script and Change:
Event1.OnServerEvent:Connect(CreeperAwMan)
Event2.OnServerEvent:Connect(WidePresident)
Event3.OnServerEvent:Connect(YankeeBrim)
To:
Event1.OnClientEvent:Connect(CreeperAwMan)
Event2.OnClientEvent:Connect(WidePresident)
Event3.OnClientEvent:Connect(YankeeBrim)
Script 1, the one inside of the button should be the server script.
The second script, which you can put in StarterPlayerScripts should be a local script.
In script 1 you should use RandomEvent:FireClient(player)
in script 2, the local script, you should use RandomEvent.OnClientEvent:Connect(ExampleFunction)