I’m trying to make a leaderboard with info from ServerStorage, but for some reason it stops updating when it goes past 1000 and gets reset to 0. However the ServerStorage info keeps going.
The leaderboard can be set to numbers greater than 1000 manually.
So currently I’m trying to make a remote function which gets the LocalPlayer name, finds it in ServerStorage to get the right player, then send the ServerStorage.LocalPlayer back to the client which updates the leaderboard.
Remote function in placed in ReplicatedStorage.
Server side script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Get reference to remote function instance
local RemoteFunction = ReplicatedStorage.UpdateLeaderboard
local function updateLeaderboard(player)
--local leaderboard = game.Players.player.leaderboard
local localPlayer = player
print(player)
return localPlayer
end
while true do
RemoteFunction.OnServerInvoke = updateLeaderboard()
wait(1)
end
Local script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Get reference to remote function instance
local RemoteFunction = ReplicatedStorage.UpdateLeaderboard
local player = game.Players.LocalPlayer
Now, this code only prints nil.
Any ideas? Is this even possible?
do not use remote functions (they’re usually exploitable, and RemoteEvents are more secure and optimized). using Remote events you do something like this
SS Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Get reference to remote function instance
local RemoteEvent = ReplicatedStorage.UpdateLeaderboard
local function updateLeaderboard(player)
--local leaderboard = game.Players.player.leaderboard
--theres no point of making a localPLayer variable, you already have the player in the parameter...
return player
end
RemoteEvent.OnServerEvent:Connect(updateLeaderboard)
Local script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Get reference to remote function instance
local RemoteEvent = ReplicatedStorage.RemoteEvent
RemoteEvent:FireServer(player)
How would I address the local player in the script?
This is the value I need when I update the player leaderboard.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Get reference to remote function instance
local RemoteEvent = ReplicatedStorage.UpdateLeaderboard
local function updateLeaderboard(player)
print(player)
local playerMoney = game.ServerStorage.PlayerMoney.player
print(playerMoney.Value)
return player
end
RemoteEvent.OnServerEvent:Connect(updateLeaderboard)
Print(player) prints my name - good.
How would one do the playerMoney line?
Possible?
This is just straight misinformation. The only hole in RemoteFunctions is client invocation because OnClientInvoke can be overwritten to never return to the server and cause a permanent hang. RemoteFunctions enable power synchronous patterns. Both RemoteEvents and RemoteFunctions are responsible for communicating cross-environment and simply determine the directionality of the communication, either one-way or two-way.
RemoteFunction would be correct here to get the LocalPlayer because the server has no concept of a local player (it is not a machine controlled by a single person), however rather than a security issue it’s more of an issue of control flow. Clients should not have any say in how a leaderboard updates or what it displays; it should be a purely server-authoritative system.
I recommend not bothering with the client when creating a leaderboard. The less you have to do on the client the better, typically.
You can get the full list of players using game.Players:GetPlayers() and get any information you need from the player to implement unto the leaderboard and adjust as necessary.
local function updateLeaderboard(player)
print(player)
local playerMoney
for i, v in pairs(playerMoney:GetChildren()) do
if player.Name == v.Name then
playerMoney = v
end
end)
print(playerMoney.Value)
return player
end
RemoteEvent.OnServerEvent:Connect(updateLeaderboard)