Behaviour is different in-game than in studio, and I don't know what to do about it

It is incredibly frustrating to make a game that works in studio, but then multiple entire script are broken when testing it in the actual game.

The main major issue caused by this is HumanoidRootPart loading. The HumanoidRootPart has loading issues on the server (especially with multiple players), and even a timeout in the :WaitForChild() does not secure a proper loading of the HumanoidRootPart. This causes many scripts to be broken.

The other issue is saving data when the player leaves. It doesn’t save the data in the actual game, only in studio. Maybe also related to HumanoidRootPart loading poorly since it is saving the Position of HumanoidRootPart, but I’m not sure because there are no errors.

my current method of identifying the part is this

local humanoidRootPart = character:WaitForChild("HumanoidRootPart", 5)
2 Likes

How are you defining your character variable anyway in the serverscript?

in both local and server scripts, I define it with
local char = plr.Character or plr.CharacterAdded:Wait()

Ah, you see, it boils down to the client and server model which I think you read about because it’s really helpful in overcoming this kind of problem especially in your future developments. Usually, for serverscripts, especially if it’s located inside the ServerScriptService, because it runs before the character could load, it’s best to define the character once it has actually loaded. Usually it is done by

game.Players.PlayerAdded:Connect(function(Player)
       local function CharacterAdded(Character)
          local HRP = Character:FindFirstChild("HumanoidRootPart")
       end
       Player.CharacterAdded:Connect(CharacterAdded)
end)

I don’t understand what you mean.
In my local script that handles the playerList, the player’s character is cloned which is triggered by a .PlayerAdded event. In here I clone the character, and try to identify the HumanoidRootPart (HRP).

characterClone.Parent = viewportFrame.WorldModel
			local hrp = characterClone:WaitForChild("HumanoidRootPart", 5)
			hrp.CFrame = CFrame.new(2, -2, -4, 0, 10, 0, 180)

Upon testing outside of studio:

On the server script, the player’s position is saved with HumanoidRootPart. It cannot seem to save the position of the humanoidrootpart.

game.Players.PlayerRemoving:Connect(function(player)
    -- dataStore
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoidRootPart = character:WaitForChild("HumanoidRootPart", 5)

How would you apply your idea to these scenarios?

Ah, I didn’t know what you were working on in the first place and that you were using a localscript. You mentioned the character is cloned when the .PlayerAdded event is triggered. It shouldn’t be, because the .PlayerAdded event is triggered when the player loads in not the character. What this means is you would’ve cloned the character when it still has its limbs and the rootpart not loaded (perhaps even when the character still has not existed completely yet) yet hence why no matter how much you wait for the HumanoidRootPart, it still doesn’t exist.

how can I wait for the character and its parts to be added then? This is what I have in the top of the playerList script. I figured CharacterAdded:Wait() would wait for the character but I guess not?

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
1 Like

I’m completely lost. This HumanoidRootPart loading killing my motivation and emotional state. This problem has occoured multiple times earlier, with no solution.

Don’t know what to write anymore. I would say I’m bad at scripting (which is partly true), however at this point the only issue in the entirety of scripting - is related to HumanoidRootPart loading.

It is so difficult to troubleshoot this subject because the behaviour is not determenistic and changes based on where you are testing it. Looking up devforum posts, and all of the information is simply false(?). People say “use this or that” and none of it works as they describe it should.

The serverscript that saves and loads the player’s data is also impossible to troubleshoot because the humanoidrootpart is not loading correctly and I can’t see the develepor log in-game when I have to leave the game for the event to trigger. Is my approach to attempting to get help with this problem also wrong?

Idk what to do

1 Like

anyways. will take a break and re-approach this later with a less broken mind.

(In case anyone replies, I’ll still listen and apply said suggestion of course)

1 Like