Remote function sends nil instead of parameter

Hello! I’m trying to make some setting so I can stop the player from growing whenever the setting is turned off and vice versa, but on the client side of the remote function I send two parameters, the player and “Growth”, however the client sends nil and the server recieves nil… I can’t figure this out.

Client Script:

local button = script.Parent

local ReplicatedStorage = game:GetService("ReplicatedStorage")

script.Parent.MouseButton1Click:Connect(function(plr)
	print("Button Presed!")
	
	local result = ReplicatedStorage:WaitForChild("Events"):WaitForChild("SettingOnOff"):InvokeServer(plr, "Growth")
	
	print(result)
	
	if result == "OFF" then
		print("Off")
		
		button.BackgroundColor3 = Color3.fromRGB(255, 48, 48)
		button.Text = "OFF"
	elseif result == "ON" then
		print("On")
		
		button.BackgroundColor3 = Color3.fromRGB(112, 255, 80)
		button.Text = "ON"
	end
end)

Server Script:

ReplicatedStorage.Events.SettingOnOff.OnServerInvoke = function(player, setting)
	local settingsFolder = player:FindFirstChild("Settings")
	print(setting)
	
	if setting == "Growth" then
		print("Setting value found!")
		
		for i, setting_ in pairs(settingsFolder:GetChildren()) do
			print("Loop started "..setting_)
			
			if setting_ == setting then
				print("Names equal")
				
				if setting_.Value == true then
					print("Setting set to False")
					
					setting_.Value = false
					
					return "OFF"
				else
					print("Setting set to True")
					
					setting_.Value = true
					
					return "ON"
				end
			end
		end
	end
end

Output:

Ok. So first things first you dont need to send the Player to the Server, the Server automatically gets the Player, so you dont have to send it when you call the function. Second off, To my knowledge, MouseButton1Click doesnt give you the Player.

How to fix?
When you Invoke the RemoteFunction, just dont put the Player as an Argument

2 Likes

It worked! Thank you so much for your help! I didn’t think that not sending the player from the client-side will make this work xD

1 Like

@notsad2 is online :pray::sob:

you need to run bro