( in studio only)Playeradded + characte added loaded fire before the client is even loaded what couses that the remote events to setup the game fails

made some new data system what fires the data thats on the server as read only on the client to use but the player added fire before the client is loaded what couses it to just refuses to load the game i didnt even touch the game manager but now it just doesnt work only i see is a skybox

PS.PlayerAdded:Connect(function(player: Player)
	warn("hi there "..player.Name.."_ID_"..player.UserId)
	repeat
		wait(1)
		warn("sjii")
	until player.CharacterAdded
	loadPlrAssets(player)
	local userId = player.UserId
	DH.load(userId)
	warn(SD)
end)

all this events + more fire when the client isnt loaded couses the game to dont see any valeu what lets it look like tier data is reseted troug it prints all data and its present

1 Like

not exactly here for the main problem of the code, but something you should do instead of using a repeat loop is just do this

local Character = player.Character or player.CharacterAdded:Wait()

now you have no reason to use a repeat loop, as this will just wait for the character, which I feel just makes the code less cluttered :D

this is the issue

.CharacterAdded isn’t a boolean that you can read, it’s an event, meaning player.CharacterAdded does… absolutely nothing! meaning… your code loops endlessly!

use frodev’s solution and it should fix lol

eiter way it seems just to only hapens in studio on the actual client it work not even with this as in some way the characrter seems to exsist but no workspace thuis no end for remote events that be fired before the scripts are loaded

also when i add breakpoints it work so theres some delay hapening in studio what just makes properly testing inposible

Did you try the code I provided? Chances are that the players character is already loaded, thus the repeat function keeps going until a new character is added.

yes

PS.PlayerAdded:Connect(function(player: Player)
	warn("hi there "..player.Name.."_ID_"..player.UserId)
	local Character = player.Character or player.CharacterAdded:Wait()
end) 

it just does this in studio

Ok your code needs the rest of the stuff that was originally there, just not the repeat loop

it have its part of a 600+ lines game manager

it like runs some functions like

local function LoadKeys(plr)
    -- do stuff
   remoteEvent:FireClient(plr, stuff)
end

so this function be called before the client is fully loaded in studio only it fires the needed remote events when the client cant resijve in studio only


PS.PlayerAdded:Connect(function(player: Player)
	warn("hi there "..player.Name.."_ID_"..player.UserId)
	local Character = player.Character or player.CharacterAdded:Wait()
        task.wait(1)
        LoadKeys(player)
end)