Really weird behaviour with RotationType

Hello Guys

I’ve been having a really weird behaviour with the RotationType enum.

This LocalScript:

local UserGameSettings_ = game:GetService(“UserGameSettings”)

local Humanoid_ = script.Parent:WaitForChild(“Humanoid”)

local CharacterRotation_ = script:WaitForChild(“CharacterRotation”)

Humanoid_.AutoJumpEnabled = false

UserGameSettings_.RotationType = CharacterRotation_.Value

Throws this error:

Workspace.robloxfoda1.HumanoidSettings:5: attempt to index nil with ‘RotationType’

(On line 5)

And this LocalScript (without the WaitForChild() on CharacterRotation):

local UserGameSettings_ = game:GetService(“UserGameSettings”)

local Humanoid_ = script.Parent:WaitForChild(“Humanoid”)

local CharacterRotation_ = script.CharacterRotation

Humanoid_.AutoJumpEnabled = false

UserGameSettings_.RotationType = CharacterRotation_.Value

Throws this error:

CharacterRotation is not a valid member of LocalScript "Workspace.robloxfoda1.HumanoidSettings

(On line 5)

CharacterRotation_ is referencing a StringVal with the Value of: Enum.RotationType.MovementRelative

What we can get from these errors is that roblox is acting like the StringVal CharacterRotation doesn’t exist, even with WaitForChild()

It’s worth noting that the LocalScript is located at StarterPlayer>StarterCharacterScripts (although I will move it to StarterPlayerScripts later, but that’s besides the point!)

Also, one question about RotationType:

The docs says it is a DataType in itself but then when you click to read about it, you get redirected to an enum index page of RotationType, how does that make any sense? For me, It’s basically saying RotationType is a DataType but then it tells me no It’s actually an enum DataType.

Thank you all for the help in advance!

1 Like

This is because UserGameSettings is not part of the natural services. You obtain it like this

local gameSettings = UserSettings():GetService("UserGameSettings")

Also, you cannot set the enum to the string of “Enum.Something.Something.” You’re betting off setting the StringValue to “MovementRelative” and doing this:

--[[
* Returns an EnumItem from a family that has the
* given name.
* @param {Enum} enum
* @param {string} name
* @returns {EnumItem}
]]
local function getEnumItemByName(enum, name)
	for _, item in pairs(enum:GetEnumItems()) do
		if (item.Name == name) then
			return item
		end
	end
end

local enumItem = getEnumItemByName(Enum.RotationType, "MovementRelative")

References: Enum (roblox.com), UserGameSettings (roblox.com), EnumItem (roblox.com)

1 Like

First off I just wanted to thank you for all the help so far!!

Also, you cannot set the enum to the string of “Enum.Something.Something.”

Why does this work then: workspace.Part.Material = Enum.Material.Concrete – By full enum (preferred method)

Also, if could answer this, why does almost every enum index has a value of its own name, what does it mean when it doesn’t have (for example, Limb) and what does value even mean in that context?

Example of an enum index with a value of its own name:

Also:

Now I’m changin the value of RotationType with the index’s number and it doesn’t work, why? Neither does changing the string to MovementRelative or CameraRelative, I will try using your method (EnumItem) soon though as I’m sure it will work, I’m just exploring all the alternatives now.

Because that isn’t a string. Your StringValue holds the string literal

"Enum.Material.Concrete"

While Enum.Material.Concrete is an EnumItem value (the quotes aren’t there). It’s an entirely seprarate and unrelated factor.

Sorry, this sentence makes no sense to me so I don’t think I can answer it. I don’t understand what you’re asking.

Most likely because the player’s default CameraModule is overwriting it every frame.

Most likely because the player’s default CameraModule is overwriting it every frame.

But the script is regarding the character’s rotation not the camera (im probably wrong), also where can I find the default CameraModule?