hi all, so my game is filtering enabled and i've come across a problem trying to 'read' stats (which are an assortment of stringvalues, intvalues, etc.) in serverstorage under a folder with the players name. in the localscript (player's gui), the line is this:
local maxStam = repStorage.Calls.ReadStat:FireServer("maxStamina")
in the server script (serverscriptservice) which connects to the event, the function looks like this:
game:GetService("ReplicatedStorage").Calls.ReadStat.OnServerEvent:Connect(function(player, stat) return game.ServerStorage[player.Name]:findFirstChild(stat).Value end)
this returns a nil value and it can't be modified in any way (as it is a nil)
any help will be appreciated!
A remote event does not return a value to the client like a remote function.
To resolve this you can either, send the data back with FireClient inside the function or use a remote function which allows you to return a value to the client.
Using a remote event example:-
-- server script local servStorage = game:GetService('ServerStorage') local rmtEvent = game:GetService('ReplicatedStorage').Calls.ReadStat rmtEvent.OnServerEvent:Connect(function(player, stat) rmtEvent:FireClient(player, stat, servStorage[player.Name]:FindFirstChild(stat).Value end) -- local script -- we need to wait until the client has the remote event local rmtEvent = game:GetService('ReplicatedStorage'):WaitForChild('Calls'):WaitForChild('ReadStat') rmtEvent.OnClientEvent:Connect(function(stat, value) print(stat, value) end) rmtEvent:FireServer("maxStamina")
Using a remote function example:-
-- server script local servStorage = game:GetService('ServerStorage') function [path to remtoe function].OnServerInvoke(plr, stat) return servStorage[player.Name]:FindFirstChild(stat).Value end -- local script local rmtFucntion = [path to remote function] print(rmtFucntion:InvokeServer('maxStamina')) -- prints max stamina
I hope this helps.