FireServer works but it won't get OnServerEvent!

Hello!

I’m working on a reactor core game.

I’m trying to make a system bootup switch.

But when I tested the script, :FireServer() seemed to work but the same doesn’t go for .OnServerEvent.

I’ve tried searching this problem on the forum but I didn’t find anything

As needed, here are the scripts. Keep in mind that both are regular scripts!

Script that uses FireServer()

You can use – not only as a comment but also executing code only for the client. (Probally an explanation on why there are comments in some scripts lol)
Example:

print("Hello world!")
--game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 100
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StartupEvent = ReplicatedStorage:WaitForChild("StartupEvent")
local Mode = 1
local Closed = script.Parent
local Open = script.Parent.Parent.Open
local Sound = script.Parent.Sound
local ClickDetector = script.Parent.ClickDetector

function onClicked(Mouse)
	ClickDetector.MaxActivationDistance = 0 
	Sound:Play()
end

function startup()
	Closed.Transparency = 1
	Closed.CanCollide = false
	Open.Transparency = 0
	Open.CanCollide = true
	--StartupEvent:FireServer(Mode)
	print("Succesfully Fired Server!")
end

ClickDetector.MouseClick:Connect(onClicked)
ClickDetector.MouseClick:Connect(startup)
Script that gets OnServerEvent()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StartupEvent = ReplicatedStorage:WaitForChild("StartupEvent")
local Status = workspace.CoreStatus.CoreStatus
local Closed = workspace.Switch.Click.Closed
local Open = workspace.Switch.Click.Open
local Sound = workspace.Switch.Click.Closed.Sound
local ClickDetector = workspace.Switch.Click.Closed.ClickDetector

StartupEvent.OnServerEvent:Connect(function(Player, Mode)
	if Mode == 1 then
		print("Succesfully Got OnServerEvent!")
	end
end)

Sorry if it’s hard to understand. For new year’s eve I was awake until 4:01 AM.

Off topic:

wait what…
wait what!

2 Likes

Use local script mate.
FireServer() won’t work on normal script.

2 Likes

image
well seems like if i use a comment it will

im gonna try it anyways

i tried using a localscript but its not even gonna print Succesfully Got OnServerEvent!

LocalScript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StartupEvent = ReplicatedStorage:WaitForChild("StartupEvent")
local Mode = 1
local Closed = script.Parent
local Open = script.Parent.Parent.Open
local Sound = script.Parent.Sound
local ClickDetector = script.Parent.ClickDetector

function onClicked(Mouse)
	StartupEvent:FireServer(Mode)
	print("Succesfully Fired Server!")
end

ClickDetector.MouseClick:Connect(onClicked)

when i try and click it wont even print

2 Likes

Can you show me both the Local Script and the Script?

(Nevermind)

1 Like

Doesn’t see a count there.
It won’t print cuz you don’t add += 1 to the Mode.
That why it won’t print
(correct me if I’m wrong)

1 Like

As @GFXBIT said, you can only use FireServer() in a Local Script.

Local

StartupEvent:FireServer(Mode)

Server

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StartupEvent = ReplicatedStorage:WaitForChild("StartupEvent")

StartupEvent.OnServerEvent:Connect(function(player,Mode)
    print("Mode: "..Mode)
end)
1 Like

Mode = 1

I think that’s enough for it to let it know what mode it is.

1 Like

Yea but I found out that I can use a comment for it to do it only on the client.
If i’m trying it without the comment it will error saying that FireServer can only be used on the client.

1 Like

Is the boot up system you are trying to create a gui?

1 Like

Well as you can see here, yea, it’s a GUI on a part.

1 Like

If you want the GUI to be seen only by one person, you can do all of that locally.

1 Like

What I’m trying to achieve is having the system bootup work. Not have a random GUI on the client pop up saying that it’s booting the systems. So that’s why I’m using :FireServer()

EDIT: Keep in mind that I tried using a LocalScript and it didn’t even print Succesfully Fired Server!

1 Like

Can you print the whole course of the Local Script?

What I mean by that is placing prints everywhere on the Local Script to catch where it blocks. Maybe the Local Script bugged before using FireServer()

1 Like

On the LocalScript there is only onClicked. I tried putting a print() before :FireServer() but still didn’t print anything. Only the Script seems to successfully use :FireServer()

1 Like

So, the print you put before the FireServer() function is not printed.

That means there is something in your local script that is blocking.

Yo try use FireClient to solve your problem RemoteEvent | Roblox Creator Documentation
ps: You should call FireClient(plr) from server script
and get it on local script with use

local remote = game:GetService("ReplicatedStorage"):FindFirstChild("YourRemoteHere")
remote.OnClientEvent:Connect(function()
     print("check")
end)

He is trying to go from the Client to the Server, from what I guessed. Using FireClient is useless for his case.

1 Like

like @heisIlan said, I wanna go from the Client to the Server. After all how does it even help? Booting the systems only on one client???

Using FireClient() might not help, but you could possibly use FireAllClients(), which calls all the player on your game.

I have a similar issue with my subtitles. If someone joins right after :FireAllClients() was called, that player won’t get the subtitles. So therefore, the new player(s) won’t see a single startup.