So I’m still a beginner with remote functions and events, nothing I’ve tried works. Where does the server script with the event code go? I’ve been using the devhub code but it still hasn’t worked for me in what I’m trying to do.
hence:
nothing in this script works when trying to call these events or functions from the client
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local dss = game:GetService("DataStoreService")
local plrDatastore = dss:GetDataStore("playerData")
local addInventoryItemEvent = Instance.new("RemoteEvent", ReplicatedStorage)
addInventoryItemEvent.Name = "AddInventoryItemEvent"
local getInventoryFunction = Instance.new("RemoteFunction", ReplicatedStorage)
getInventoryFunction.Name = "GetInventoryFunction"
--local access to adding inventory items. otherwise use inventory overrides for server side additions.
--saves to player's inventory table in the datastore accordingly
local function addInventoryItemFired(plr, reference) --reference is the item codename
local playerData
local userId = game.Players:GetUserIdFromNameAsync(plr.Name)
playerData = plrDatastore:GetAsync(userId)
table.insert(playerData["inventory"], #playerData["inventory"]+1, tostring(reference))
plrDatastore:SetAsync(userId, playerData)
end
addInventoryItemEvent.OnServerEvent:Connect(addInventoryItemFired())
-- return the player's inventory
-- returns table
local function getInventoryInvoked(plr)
local playerData
local userId = game.Players:GetUserIdFromNameAsync(plr.Name)
playerData = plrDatastore:GetAsync(userId)
playerData = playerData["inventory"]
return playerData
end
getInventoryFunction.OnServerInvoke = getInventoryInvoked