Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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!

0
Do you need information send back to the client? if not you should use a remote event instead. gamingwithjbthepro 76 — 3y
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 CheeseBallGuy11 12 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

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.

0
Doesn't work either way CheeseBallGuy11 12 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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

Answer this question