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

RemoteEvents, incorrectly sending variant arguments?

So I am making a light switch with FE turned on. However the client keeps sending the variant arguments jumbled and some missing. What I am trying to do is the following. A localscript detects when the player clicks on something. It checks if it has the correct child of the switch so it doesn't miss fire the event. That part works correctly, it works all the way. Except as stated above the arguments are messed up.

Server Script in ServerScriptService:

game.ReplicatedStorage.Lights.OnServerEvent:connect(function(Varg1, Varg2, Varg3)
	local Light = Varg1
	local Mode = tostring(Varg2)
	local Switch = Varg3
	print(Light)
	print(Mode)
	print(Switch)
	if Mode == 'On' then
		--On code
		Light.BrickColor = BrickColor.Green()
		Switch.BackgroundColor3 = Color3.new(0/255,100/255,0/255)
		Switch.BorderColor3 = Color3.new(0/255,100/255,0/255)
		Switch.Text = 'ON'
	elseif Mode == 'Off' then
		--Off code
		Light.BrickColor = BrickColor.Red()
		Switch.BackgroundColor3 = Color3.new(170/255,0/255,0/255)
		Switch.BorderColor3 = Color3.new(170/255,0/255,0/255)
		Switch.Text = 'Off'
	end
end)

Local Script in StarterPlayerScripts:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local function toggleLightSwitch(Hit)
	local Light = Hit.Parent:FindFirstChild('Light')
	local Switch = Hit.Parent.Switch.SurfaceGui.Frame.TextButton
	if Switch.BackgroundColor3 == Color3.new(170/255,0/255,0/255) then
		game.ReplicatedStorage.Lights:FireServer(Player, Light, 'On', Switch)
	else
		game.ReplicatedStorage.Lights:FireServer(Player, Light, 'Off', Switch)
	end
end

Mouse.Button1Down:connect(function()
	if Mouse.Target.Parent:FindFirstChild('Light') and Mouse.Target.Parent:FindFirstChild('Switch') then
		toggleLightSwitch(Mouse.Target)
	end
end)

Any suggestions and help is much appreciated. :)

1 answer

✓ Accepted answer

You got confused.

Your code currently maps as

FireServer (Player TargetPlayer, var ...) >> OnServerEvent -> 
	var ...

Which is wrong, because that's the mapping for FireClient >> OnClientEvent. What it should really look like is

FireServer (var ...) >> OnServerEvent ->
	Player PlayerWhoFired,
	var ...

Just sort out your function parameters and connection arguments and you'll be fine.

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