I'm absolutely horrible at debugging, so I'm sorry if the fix is an annoyingly easy. I made a script that's /supposed/ to check if the player whose data I'm editing is in the game so it can edit the in-game value too-- and if they aren't there just normally change the data.. but each time I enter someone who isn't in the game it checks for them anyway and then tells me "so and so is not a valid member of players"
I've rewritten this same script a bunch of times but whatever I tried gives the same output.
local PDS = game:GetService("DataStoreService"):GetOrderedDataStore("NumberOfPosts")
local UserTB = script.Parent.Parent.UserTB
local ValueTB = script.Parent.Parent.ValueTB
script.Parent.MouseButton1Click:connect (function()
if game.Players[UserTB.Text] then
local key = UserTB.Text
local S = tonumber(ValueTB.Text)
game.Players[UserTB.Text].leaderstats.Posts.Value = tonumber(ValueTB.Text)
PDS:SetAsync (key, S)
print("Value for " .. UserTB.Text .. " has been changed to" .. ValueTB.Text)
else
local key = UserTB.Text
local S = tonumber(ValueTB.Text)
PDS:SetAsync (key, S)
print("Value for " .. UserTB.Text .. " has been changed to" .. ValueTB.Text)
end
end)
could you tell me how I can fix this and how I can avoid this problem in the future? D;

1 comment
I may be wrong, but i spotted a space on line 6, with the function. I dont think there should be a space.