What do you want to achieve?
I’d like a return some information from a dictionary via a RemoteEvent.
What is the issue?
It’s not returning a value (see error)
What solutions have you tried so far?
I’m not really sure what else to try, looked through some other posts, but haven’t found much relating to this.
The Server Script
game.ReplicatedStorage.RemoteEvents.RequestData.OnServerEvent:Connect(function(Player, Data)
if Player then
-- Data in leaderstats
if Data == "Level" then
return(ServerData[Player].leaderstats.Level)
elseif Data == "Rebirths" then
return(ServerData[Player].leaderstats.Rebirths)
-- Data in hiddenstats
elseif Data == "Coins" then
return(ServerData[Player].hiddenstats.Coins)
elseif Data == "OwnedTags" then
return(ServerData[Player].hiddenstats.OwnedTags)
elseif Data == "EquippedTag" then
return(ServerData[Player].hiddenstats.EquippedTag)
elseif Data == "OwnedTrails" then
return(ServerData[Player].hiddenstats.OwnedTrails)
elseif Data == "EquippedTrail" then
return(ServerData[Player].hiddenstats.EquippedTrail)
end
end
end)
Just some context for the above. ServerData contains all of the data for the players in the current server.
The Local Script
while wait() do
script.Parent.Text = tostring(game.ReplicatedStorage.RemoteEvents.RequestData:FireServer("Coins"))
end
I’m not sure if this’ll help, but I believe you need to use a RemoteFunction and invoke it via InvokeServer
game.ReplicatedStorage.RemoteEvents.RequestData.OnServerInvoke = function(Player, Data)
if Player then
-- Data in leaderstats
if Data == "Level" then
return ServerData[Player].leaderstats.Level
elseif Data == "Rebirths" then
return ServerData[Player].leaderstats.Rebirths
-- Data in hiddenstats
elseif Data == "Coins" then
return ServerData[Player].hiddenstats.Coins
elseif Data == "OwnedTags" then
return ServerData[Player].hiddenstats.OwnedTags
elseif Data == "EquippedTag" then
return ServerData[Player].hiddenstats.EquippedTag
elseif Data == "OwnedTrails" then
return ServerData[Player].hiddenstats.OwnedTrails
elseif Data == "EquippedTrail" then
return ServerData[Player].hiddenstats.EquippedTrail
end
end
end
while wait() do
script.Parent.Text = tostring(game.ReplicatedStorage.RemoteEvents.RequestData:InvokeServer("Coins"))
end
You’d of course hae to change the RemoteEvent RequestData into a RemoteFunction and change some stuff around
you might see some lag later down the line since you’re using a while wait do and calling server invoke. thats alot of requests. You could just check on the server any time their coins are changed and fire an event to the client to change the text. also on respawn so it updates first thing.