CFrame is not a valid member of Player "Players.ForgetableLife"

	for _, player in game:GetService("Players"):GetPlayers() do
		local humanoidRootPart = player.Character.PrimaryPart
		if humanoidRootPart and Object then
			humanoidRootPart.CFrame = Object.CFrame
		end
	end

the error has me puzzled since the character and humanoidrootpart do not correspond with each other

5 Likes

My guess is that the player hasn’t loaded in when you called this?

3 Likes

That might be so but how would i fix that?

You should probably define the character like below so it only runs the code when the character has loaded:

local character = player.CharacterAdded:Wait()
2 Likes

Instead of getting players you can try .PlayerAdded and .CharacterAdded

1 Like

For some reason its just stuck theres no errors nor is it doing anything

It means that the character is never getting added or player is nil

3 Likes

ohh no i realize why

game:GetService("ReplicatedStorage").CreateDungeon.OnServerEvent:Connect(function(Object)
	TransitionModule.Transition()
	task.wait(0.5)
	for _, player in game:GetService("Players"):GetPlayers() do
		local character = player.CharacterAdded:Wait()
		local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
		if humanoidRootPart and Object then
			humanoidRootPart.CFrame = Object.CFrame
		end
	end
	CreateRoom(1)
	task.wait(0.5)
	AlreadyRooms:FindFirstChild("Dungeon"..PreviousRoom):Destroy()
	TransitionModule.TransitionEnd()
end)

the character is already added

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

Try changing to this.

I don’t actually believe that is the problem right here. The error is CFrame is not a valid member of Player “Players.ForgetableLife”, which means the code is trying to get the CFrame of a Player object. The only two times the code tries to get the CFrame of something is with humanoidRootPart and with Object. humanoidRootPart isn’t nil, because then the error would be attempt to index nil with 'CFrame' so that makes me believe Object is the issue. What exactly is Object supposed to be, and what is it actually in the code?

1 Like

Do this:

game:GetService("ReplicatedStorage").CreateDungeon.OnServerEvent:Connect(function(Object)
	TransitionModule.Transition()
	task.wait(0.5)
	for _, player in game:GetService("Players"):GetPlayers() do
		local character = player.Character or player.CharacterAdded:Wait()
		local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
		if humanoidRootPart and Object then
			humanoidRootPart.CFrame = Object.CFrame
		end
	end
	CreateRoom(1)
	task.wait(0.5)
	AlreadyRooms:FindFirstChild("Dungeon"..PreviousRoom):Destroy()
	TransitionModule.TransitionEnd()
end)
1 Like

Its a part inside a model

local Character = script.Parent

local Humanoid = Character.Humanoid

local Player = game:GetService("Players"):GetPlayerFromCharacter(Character)

Humanoid.Touched:Connect(function(hit)
	if hit.Name == "Doorway" then
		if hit.Parent.CanEnter.Value == true then
			game:GetService("ReplicatedStorage").CreateDungeon:FireServer(hit.Parent.TpEnd)
			hit.Parent.CanEnter.Value = false
		end
	end
end)

This is the line which causes the error. The first argument of OnServerEvent will always be the player, and the ones after that will be the actual arguments fired in the event. Right now, the Object variable will be the Player who fired the event. To fix, replace the line with this:

game:GetService("ReplicatedStorage").CreateDungeon.OnServerEvent:Connect(function(PlayerWhoSentEvent, Object)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.