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

PlayerDataStore - LocalScript or Script?

Asked by 6 years ago
Edited 6 years ago

When calling PlayerDataStore to store information (like stats for an rpg and whatnot), do you have to use a script? Many sites I looked up said it won't work otherwise. If so, how do you get the player to use in "PlayerDataStore:GetSaveData(player)" in the regular script? If you can use a LocalScript, how do I remove this error?

Error: "PlayerDataStore requested on the client, is a server-only module."

0
Error is saying that PlayerDataStore can't be requested on the client (local script), and can only be requested on a server-only module hellmatic 1523 — 6y
0
Never tried PlayerDataStore, but attempt to use a script. hellmatic 1523 — 6y
0
I don't know how I can get the player from a regular script. Is there any straight forward way? Thanks for replying. Hamrhed2 4 — 6y
0
game.Players.PlayerAdded:Connect(function(Player) --do stuff end) Lord_CthuIhu 2 — 6y
0
So can I make that a variable instead of a function? Do I just do something like "player = Player" in the function then end it and I can use the variable "player"? Hamrhed2 4 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
game:GetService("Players").PlayerAdded:Connect(function(plr) -- plr is our player variable
    -- PlayerDataStore:GetSaveData(plr) -- The variable used above
end)
0
I changed my way of doing it do "game.Players.PlayerAdded:Connect(function(plr) local PlayerDataStore = require(game.ServerScriptService.PlayerDataStore) saveData = PlayerDataStore:GetSaveData(plr) end)" but now I get the error "attempt to index global 'saveData' (a nil value)"? Is it because I'm testing it in studio and not in-game? Hamrhed2 4 — 6y
Ad

Answer this question