Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does it think I'm trying to pass the player as an argument?

Asked by 7 years ago
Edited 7 years ago

I'm trying to fire a remote event (from the client), and I want it to return the first value of the table I have saved in a datastore, but it thinks 'slot' is the player, when it is not.

LocalScript:

wait(2)
script.Parent.CharName.Text = game.Lighting.Remotes.ClientToServer.GetCharName:FireServer({"1"}, game.Players.LocalPlayer, game.Players.LocalPlayer.Char)

ServerScript:

game.Lighting.Remotes.ClientToServer.GetCharName.OnServerEvent:connect(function(slot, plr, charf)
    local ds = game:GetService("DataStoreService"):GetDataStore("datastore["..slot[1].."]"..plr.UserId)
    local key = "rpg"..plr.UserId
    local vals = ds:GetAsync(key)
    print(vals)
    print(vals[1])
    return vals[1]
end)

I'm just super confused. Thanks if you could help!

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

This is because when you fire the server with a remote event, the first argument that the server receives is ALWAYS the player that fired the server, and you don't need to include the player when you fire the server since it's automatically the first argument. So your client script should be like this...

wait(2)
script.Parent.CharName.Text = game.Lighting.Remotes.ClientToServer.GetCharName:FireServer({"1"}, game.Players.LocalPlayer.Char)

...and your server script should be like this:

game.Lighting.Remotes.ClientToServer.GetCharName.OnServerEvent:connect(function(plr, slot, charf)
    local ds = game:GetService("DataStoreService"):GetDataStore("SimpDragMattRPG["..slot[1].."]"..plr.UserId)
    local key = "samibryce-rpg"..plr.UserId
    local vals = ds:GetAsync(key)
    print(vals)
    print(vals[1])
    return vals[1]
end)

Let me know if it worked !

0
Thank you! Operation_Meme 890 — 7y
Ad

Answer this question