Hello all, I am in need of support. I have been trying for days to find a solution for this error. Basically, the player variable returns nil, and I am literally unable to find why it's nil. I've scoured the internet for answers but most of them are just specific to the people who made the question... anyways, can someone help me fix this dreadful error?
As always with Data Stores, this is a server script.
01 | local dss = game:GetService( "DataStoreService" ) |
02 | local WindowsActivated = dss:GetDataStore( "WindowsActivated" ) |
03 |
04 | local frame = script.Parent |
05 | --local t = frame.activateText |
06 | local value = script.Parent.Parent.activation.activated |
07 |
08 | game.Players.PlayerAdded:Connect( function (plrobj) |
09 | plr = game.Players:FindFirstChild(plrobj) |
10 | end ) |
11 |
12 | while true do |
13 | wait( 0.2 ) |
14 |
15 | local success, errormsg = pcall ( function () |
Thanks in advance.
There is a problem in line 9 and
If there is more than one player (if you are planning to have 1 player per server then you don't need to), the loop won't loop for the other player. Attempt putting the loop inside of the event
Script for more than one player
01 | local dss = game:GetService( "DataStoreService" ) |
02 | local WindowsActivated = dss:GetDataStore( "WindowsActivated" ) |
03 |
04 | local frame = script.Parent |
05 | --local t = frame.activateText |
06 | local value = script.Parent.Parent.activation.activated |
07 |
08 | game.Players.PlayerAdded:Connect( function (plrobj) |
09 | local plr = plrobj -- Here is the problem. Before you were trying to do findfirstchild and you put an instance instead of a string. You can also just do plr line 8 instead of plrobj |
10 | while true do |
11 | wait( 0.2 ) |
12 |
13 | local success, errormsg = pcall ( function () |
14 | WindowsActivated = WindowsActivated:GetAsync(plr.UserId.. "activated" ) |
15 | end ) |
Script for one player per server
01 | local dss = game:GetService( "DataStoreService" ) |
02 | local WindowsActivated = dss:GetDataStore( "WindowsActivated" ) |
03 |
04 | local frame = script.Parent |
05 | --local t = frame.activateText |
06 | local value = script.Parent.Parent.activation.activated |
07 | local plr |
08 | game.Players.PlayerAdded:Connect( function (plrobj) |
09 | plr = plrobj |
10 | end ) |
11 |
12 | while true do |
13 | wait( 0.2 ) |
14 |
15 | local success, errormsg = pcall ( function () |