I got this in a regular ServerScript to try and add 1 to their RoundsPlayed in Datastore2, but I keep getting the else statement.
If I remove the else part in the script I get nothing in the console.
V Script V
for i, v in pairs(game.Workspace.CurrentlyPlaying:GetChildren()) do
local thatPlayer = game:GetService("Players"):FindFirstChild(v)
if thatPlayer then
print(v.Name.." gains a round")
local RoundsPlayed = DataStore2("Rounds", v)
RoundsPlayed:Increment(1)
else
print("Couldn't find thatPlayer, (v) = "..tostring(v))
end
end
The reason this doesnât work is because you are only passing âvâ through the :FindFirstChild() parameter, which is not a string. Iâm assuming that this folder contains the characters of the players. If so, you can use :GetPlayerFromCharacter() and pass the character instance. This should return the player if they are in game and your code should work like normal!
TLDR:
Switch this:
local thatPlayer = game:GetService("Players"):FindFirstChild(v)
to this:
local thatPlayer = game:GetService("Players"):GetPlayerFromCharacter(v)
UserId is not a valid member of Model âWorkspace.CurrentlyPlaying.eggspIicitâ - Server - DataStore2:530
Script âServerScriptService.DataStore2â, Line 530 - function __call - Studio - DataStore2:530
Script âServerScriptService.DataStore2â, Line 491 - function __call - Studio - DataStore2:491
Script âServerScriptService.Mainâ, Line 88 - Studio - Main:88
Youâre trying to get a property of the Player out of the Character.
Replace v in local RoundsPlayed = DataStore2("Rounds", v) with thatPlayer. This was a problem as a result of your code, and not the fix you were given.