So I'm transfering the player trough an remote event (I think thats possible) But it is giving me an error when i try to fire a remote event from the server into the client with that player argument i got from the client remote event i send into the server.
Here's my server script:
local inv = {}
local nextSlot = 1
local currentSlot = 1
RemoteEvents.UpdatePlayer.OnServerEvent:connect(function(plr)
player = plr
end)
local function checkIfEmpty(empty, item)
if inv[nextSlot] ~= nil then
nextSlot = nextSlot + 1
currentSlot = currentSlot + 1
if inv[nextSlot] ~= nil then
nextSlot = nextSlot + 1
end
empty = true
if nextSlot <= 10 then
RemoteEvents.ToolHotbar:FireClient(player, nextSlot, empty, item)
inv[nextSlot] = item
else
print("Your inventory is full please empty it.")
end
else
print("Slot"..nextSlot.. " Is empty, Adding item...")
empty = true
RemoteEvents.ToolHotbar:FireClient(player, nextSlot, empty, item)
inv[nextSlot] = item
end
end
function addItem(empty, item)
checkIfEmpty(empty, item)
end
addItem(false, "Dirt")
addItem(false, "Dirt")
addItem(false, "Dirt")
addItem(false, "Dirt")
addItem(false, "Dirt")
addItem(false, "Dirt")
Client Script:
local rep = game.ReplicatedStorage
local items = rep.items
local Events = rep.Events;
local RemoteEvents = Events.RemoteEvents;
local gui = script.Parent:WaitForChild("ScreenGui")
local Toolbar = gui.Toolbar
RemoteEvents.ToolHotbar.OnClientEvent:connect(function(slot, empty, item)
if empty then
local imageID = items[item]:FindFirstChild("imageID").Value
Toolbar["Slot"..slot].itemImage.Image = "rbxassetid://"..imageID
Toolbar["Slot"..slot].itemImage.Visible = true
end
end)
RemoteEvents.UpdatePlayer:FireServer(plr)
Error:
17:05:15.592 - FireClient: player argument must be a Player object
17:05:15.593 - Stack Begin
17:05:15.593 - Script 'ServerScriptService.MainScript', Line 40 - upvalue checkIfEmpty
17:05:15.594 - Script 'ServerScriptService.MainScript', Line 46 - global addItem
17:05:15.594 - Script 'ServerScriptService.MainScript', Line 49
17:05:15.594 - Stack End

10 comments
Is this the FULL script?
I edited the script so now it's the full script except some normal local plr, varible in the client script and some varibles in the server script that dosn't matter
The first argument of remote events from client-> server is already the player, you don't need to add another argument
Totaly knew that + that dosn't fix anything doe
Try removing the (plr) argument
Okay let me put it this way...you have a remote event that "updates" the player, but your script meanwhile in the background also runs some functions in the background using the player argument regardless of whether or not "player" is nil causing your error
Yeah, But i can't see one function who runs at the same time using the player causing it to be nil
...you are calling your local function addItem which calls checkIfEmpty like 6 times at the bottom completely irrelevant of the event being ran which yes, uses player
The addItem function isn't irrelevant cause thats the line of code that spawns the items into your inv. CheckIfEmpty dosn't use the player unless when i fire the ToolHotbar and thats the hole problem i started all this with.
It's irrelevant to the event, your event does nothing more than update the player variable but outside of the event these local functions are running automatically