Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

PlayerDataStore - LocalScript or Script?

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."

5 comments

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

0

Never tried PlayerDataStore, but attempt to use a script.

0

I don't know how I can get the player from a regular script. Is there any straight forward way? Thanks for replying.

0

game.Players.PlayerAdded:Connect(function(Player) --do stuff end)

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"?

1 answer

game:GetService("Players").PlayerAdded:Connect(function(plr) -- plr is our player variable
    -- PlayerDataStore:GetSaveData(plr) -- The variable used above
end)

1 comment

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?

This discussion is preserved as it was. New answers, comments, and votes are closed.