I dont know how to transfer player data to a localscript, I tried using a remote event and returning the data but it just gives me an error: Attempt to index nil with cash, here is the onserverevent: getdata.OnServerEvent:Connect(function(plr)
return data[plr.UserId]
end)
What does data table contains and can u show the local script
yeah, i can show you the localscript
local plr = game:GetService(“Players”).LocalPlayer
local RS = game:GetService(“ReplicatedStorage”)
local remotes = RS:WaitForChild(“Remotes”)
local functions = RS:WaitForChild(“Functions”)
local getdata = remotes.GetData
function givecash(plr)
local data = getdata:FireServer(player)
data.Cash += 10
end
remotes.CashEvent.OnClientEvent:Connect(givecash)
also the data table only contains cash as of right now.
The parameter is plr but you are firing server to “player”. Typo? Also just give the cash in the server, exploiters will cheese the system if you do this in the client
i will try changing the parameter
Can u show me how the data table should be assuming this works cause i might have found the solution
yes i can just let me try drmysteries solution
It doesnt matter since remotr events pass player as first argument always
He’s receiving it on the client, there is no player param. That plr param in the function is actually useless since it would be nil if he didn’t define the local player up there
doesnt work, it just gives the same error
He is firing from client side first
also im sorry about this lol, im new to luau
Can u show me what i ve said earlier
Thought you were talking about the receiving thing. Anyway, you aren’t supposed to give a player param when you’re firing server, you will receive it on server side
yeah, i will show the script right now
local dss = game:GetService(“DataStoreService”)
local GlobalData = dss:GetDataStore(“GlobalData”)
local getdata = game:GetService(“ReplicatedStorage”).Remotes:WaitForChild(“GetData”)
local Playerdata
local data
game.Players.PlayerAdded:Connect(function(player)
local id = player.UserId
local success, result = pcall(function()
data = GlobalData:GetAsync(id)
end)
if success then
print(“Data loaded”)
else
print(“Error loading data”)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local id = player.UserId
local data = {
[“Cash”] = 15
}
local success, result = pcall(function()
GlobalData:SetAsync(id, data)
end)
if success then
print("Saved")
else
warn(result)
end
end)
getdata.OnServerEvent:Connect(function(plr)
return data[plr.UserId]
end)
Euh… first change local data to local data = {}
If the problem still occurs can u add print to the data of the plr
getdata.OnServerEvent:Connect(function(plr)
print(data[plr.UserId])
return data[plr.UserId]
end)