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

RemoteFunction to send information from local to server script not working?

I'm trying to send a players user from a local script in StartGui to a server script in workspace using a RemoteFunction but I get 2 error messages, either 'attempt to index nil with InvokeServer' or 'attempt to index nil with OnServerInvoke'. I've used the devs hub reference to make this but I just can't figure out why it's not working.

local script:

local Player = game:GetService("Players").LocalPlayer.Name
local Playeruse = game.Workspace:WaitForChild(Player)
if Playeruse:FindFirstChild(Player) == true then
	print(Playeruse)
end

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("Remote")

local mouse = game.Players.LocalPlayer:GetMouse()
mouse.KeyDown:connect(function(key)
	key = key:lower()
		if key == "f" then
print("Keypressed")
		
		local Playersname = Remote:InvokeServer(Playeruse)
		print("ServerFired")
		print(Playeruse)
		
	end
end)

server script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteFunction = ReplicatedStorage:WaitForChild("Remote")


local function Playersname(Playeruse)
	print(player)
	
local player = game.Workspace:FindFirstChild(Playeruse) 
local Headlamp = player:FindFirstChild("Headlamp")
local LightEmitter = Headlamp:FindFirstChild("LightEmitter")
local Spotlight = LightEmitter:FindFirstChild("SpotLight")

	if Spotlight.Enabled == false then
		Spotlight.Enabled = true
	else
		if Spotlight.Enabled == true then
			Spotlight.Enabled = false
		end
		
end
end

Remote.OnServerInvoke = Playersname(Playeruse)

It does succeed in getting the players user, and registering the f key press, the only problem with both scripts is the RemoteFunction stuff, I would really appreciate it if someone could point out what I'm doing wrong. Thanks!

2 comments

0

Do you need information send back to the client? if not you should use a remote event instead.

0

Ok yeah I forgot about that, I'm using remote event now, It's sending the players name, the server script is picking it up but it can't find the player in the workspace

2 answers

I believe it is because the player is already a passed argument in the InvokeServer() function, so you don't need to add playerUse to it.

1 comment

0

Doesn't work either way

I just should've used remote event instead, I can get the name now

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