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

Why is the client not firing the server?

Ok, so I am making a school bus spawner. There is a GUI (Stored in StarterGUI) that has a frame with a bunch of buttons, in each of those buttons there's a local script that fires the server with the specific school bus type. In the handler for the RemoteEvent (Stored in replicated storage), it should detect when the OnServerEvent, and look for the bus type that got sent through the local script and spawn the specific one in. But it dosen't, and no output errors either. I tried messing with it for an hour straight and nothing.

LOCALSCRIPT (The parent for this script is the button)

local SelF = script.Parent.Parent


script.Parent.MouseButton1Down:connect(function()
	game.ReplicatedStorage.BusSpawner:FireServer("CEOLD")
	SelF.Visible = false
end)

SERVER SCRIPT (The parent for this script is the RemoteEvent)

local CE = script.Parent.Parent.ICCE300
local CEWC = script.Parent.Parent.ICCE300WC
local CEOLD = script.Parent.Parent.ICCE2004
local C2 = script.Parent.Parent.THOMASC2
local C2WC = script.Parent.Parent.THOMASC2HANDICAP


local function ServerTriggered (bus)
	if bus == "ICCE" then
		local busce = CE:Clone()
		busce.Parent = workspace
	elseif bus == "ICCEWC" then
		local buscewc = CEWC:Clone()
		buscewc.Parent = workspace
	elseif bus == "CEOLD" then
		local busceold = CEOLD:Clone()
		busceold.Parent = workspace
	elseif bus == "C2" then
		local busc2 = C2:Clone()
		busc2.Parent = workspace
	elseif bus == "C2WC" then
		local busc2wc = C2WC:Clone()
		busc2wc.Parent = workspace
	end
end
script.Parent.OnServerEvent:Connect(ServerTriggered)

I definetly know its a problem with the client because I tried debuging the server script with print("server") before the if statement and nothing came up.

2 answers

✓ Accepted answer

the first parameter of a remote event will always be the player who fired that remote event

for example, if you did RemoteEvent:FireServer(arg1, arg2) on the client, the server would get playerWhoFired, arg1, and arg2

-- localscript
local RemoteEvent = path.to.RemoteEvent

RemoteEvent:FireServer("foo", "bar")

-- script
local RemoteEvent = path.to.RemoteEvent

RemoteEvent.OnServerEvent:Connect(function(playerWhoFired, arg1, arg2)
	-- even though we never sent that data to the server, the server knows who fired the event
	print(playerWhoFired, arg1, arg2) --> [your username here], foo, bar
end)

also, scripts only run in the workspace and ServerScriptService, so you'll have to move the script to one of those two places (preferably ServerScriptService, because having scripts in the workspace is kind of nasty)

1 comment

0

Thank you so much! Knowing this now could probably fix a bunch of other things I gave up on lol.

Move the script to server script service. And change the bottom line to


game.replicatedstorage.BusSpawned.OnServerEvent:Connect(ServerTriggered)

You also need to change the top variables since the script is no longer in the remote event. Scripts should always be serverscript service (most of the time lol) Also change servertriggered to


local function ServerTriggered(player, bus)

Because when you fire to the server it sends player as a parameter automatically.

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