Printing "nil" instead of "ON" or "OFF"

I am trying to use only one event for something in my game, so when I fire it to the server, i send the state (ON or OFF) and the player, like this

event:FireServer("ON", player)

and in the server script, I pick it up like this

event.OnServerEvent:Connect(function(state, player)

end)

I then tried printing state like this

print(state)

but it returned nil

here is my entire code

local:

local player = game.Players.LocalPlayer
local debounce = false
local character = player.Character
local root = character:WaitForChild("HumanoidRootPart")
local mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")
local spell = false
local active = false
local event = game.ReplicatedStorage.AbilityEvents.EXCLUSIVE.Reboundus

player.Chatted:Connect(function(msg)
	if string.find(msg:lower(),"reboundus") ~= nil and debounce == false and spell == false and player.Character.Humanoid.ragdoll.Value == false and not player.Character.Humanoid.PlatformStand and player.Character.Humanoid.Health > 0 and active == false then
		spell = true
		active = true
		print("said reboundus, enabled")
		if player:GetRankInGroup(11954854) >= 200 and player.Team.Name ~= "Visitors" then
			local fade = player.PlayerGui.SPELLFLASH.Blue
			local tween = game.TweenService:Create(fade, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {["BackgroundTransparency"] = 0})
			local tween2 = game.TweenService:Create(fade, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {["BackgroundTransparency"] = 1})
			event:FireServer("ON", player)
			print("fired reboundus ON")
			wait(2)
			spell = false
		end
	end
end)

player.Chatted:Connect(function(msg)
	if string.find(msg:lower(),"rebounda") ~= nil and debounce == false and spell == false and player.Character.Humanoid.ragdoll.Value == false and not player.Character.Humanoid.PlatformStand and player.Character.Humanoid.Health > 0 and active == true then
		spell = true
		active = true
		print("said rebounda, disabled")
		if player:GetRankInGroup(11954854) >= 200 and player.Team.Name ~= "Visitors" then
			local fade = player.PlayerGui.SPELLFLASH.Blue
			local tween = game.TweenService:Create(fade, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {["BackgroundTransparency"] = 0})
			local tween2 = game.TweenService:Create(fade, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {["BackgroundTransparency"] = 1})
			event:FireServer("OFF", player)
			print("fired rebounda OFF")
			wait(2)
			spell = false
		end
	end
end)

server:

local event = game.ReplicatedStorage.AbilityEvents.EXCLUSIVE.Reboundus

event.OnServerEvent:Connect(function(state, player)
	print(player.Name)
	print("recieved reboundus")
	print(state)
	if state == "ON" then
		print("reboundus fired on")
		local val = Instance.new("BoolValue")
		val.Name = "ReboundusActive"
		val.Value = true
		val.Parent = player.Character
		print("added value")
		game.ReplicatedStorage.Events.SpellFOV:FireClient(player)
	elseif state == "OFF" then
		print("reboundus fired off")
		if player.Character:FindFirstChild("ReboundusActive") then
			player.Character.ReboundusActive:Destroy()
			game.ReplicatedStorage.Events.SpellFOV:FireClient(player)
			print("reboundus value destroyed")
		end
	end
end)

on the print statements on the server, this prints:
image

I had the exact same issue if i tried FireServer(player, "ON")

1 Like

Try making ‘player’ your first parameter instead of second.

1 Like

I mentioned that I tried this before and got the same error, state still printed as nil

Have you tried just removing ‘player’ from the call completely? It’ll automatically send the local player to the server.

2 Likes

I just tried this and got the exact same thing.
image

The first argument on the server side is automatically the player. Change your code to look like:

LocalScript

event:FireServer("ON")

ServerScript

event.OnServerEvent:Connect(function(player, state)

end)
2 Likes

Try moving ‘player’ to the first parameter now. (on the server)

2 Likes

It worked when I switched player to the first parameter. Thank you!

and thank you too @SevenDevelopment for your responses and help

1 Like

Glad you could fix it quick! Also, consider replacing ‘on’ and ‘off’ with true & false. You could have something like…

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.