Can someone explain this code to me?

I was looking through the Creator Documentation and found a sample code made by Roblox. In this code, I noticed some unfamiliar syntax and was wondering what is was.

Variable Declarations with “: :”

local player = Players.LocalPlayer :: Player
local playerScripts = player:FindFirstChild("PlayerScripts") :: PlayerScripts
local playerModuleBase = playerScripts:WaitForChild("PlayerModule") :: ModuleScript
local playerModule = require(playerModuleBase) :: any

Functions with “:”

local function setCameraControlsEnabled(enabled: boolean)
	-- Toggle between Scriptable and Custom camera types to disable or enable camera control respectively
	if Workspace.CurrentCamera then
		Workspace.CurrentCamera.CameraType = if enabled then Enum.CameraType.Custom else Enum.CameraType.Scriptable
	end
end

local function setDoorOpen(door, open: boolean)
	-- When a door is open, it should be able to be walked through and the proximity prompt should be disabled
	-- When the door is closed, the opposite applies
	door.Entrance.ProximityPrompt.Enabled = not open
	door.Entrance.CanCollide = not open
end

Could someone please explain these things to me and their potential uses?

1 Like
1 Like

Not sure about the first one, but the second one will throw an error if the function is called by the wrong instance. For example, setDoorOpen(workspace.Door, "string") would throw an error.

1 Like

No it wouldn’t throw an error its just for the typechecker, at runtime nothing will happen, what its for is specifying what type it is in the autocomplete, and for the first one its to set the type of an expression

1 Like

I don’t see why type checking is necessary though… Like for this line:
local player = Players.LocalPlayer :: Player

The player is always going to be of type, Player. I can’t think of any instances where Player.LocalPlayer would return any type other than “Player”. Same thing with PlayerScripts.

image
If u look at it its got a question mark which means its could potentially be something else, and my guess is just that the autocomplete will always assume its a player

1 Like

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