How Do i Make All The Players Be Teleported To A Part At A Certain Time Of Day

When Its A Certain Time Of Day I tryed To Make A Code To teleport All The Players In The Game To a Part
Here Is My Script

local lighting = game:GetService("Lighting)
lighting:GetPropertyChangedSignal(“TimeOfDay”):Connect(function()
if lighting.TimeOfDay == “17:00:00” then

– I don’t understand the script to teleport the players to a part called TeleportTo

   end

end)

You could filter through all characters and do Character:MoveTo(TeleportTo.Position). This moves the root part of a model to the destination.

As @Vixillity mentioned, a Model has a member function :MoveTo() that takes a Vector3 as a parameter. The parameter you would pass through is the position of the part you want the players to teleport to.

Since our character is a Model, we can access this :MoveTo() function. To get the character of a player, we could loop through every player currently in the game by using a for loop and the :GetPlayers() function, which is a member function of the Players object. We can access this just as you do the Lighting object, by using game:GetService("Players").

I noticed you forgot to add another " to the end of the :GetService() parameter of lighting, so I’ve included a fix to this in the solution below (teleportToPart is a part I made located in the workspace on my project to test this).

local lighting = game:GetService("Lighting")
local players = game:GetService("Players")

local teleportToPart = workspace:WaitForChild("teleportToPart")

lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(function()
	if lighting.TimeOfDay == "17:00:00" then
		for _, player in ipairs(players:GetPlayers()) do
			local character = player.Character
			
			character:MoveTo(teleportToPart.CFrame.p)
		end
	end
end)

I hope this helps, if you have any questions regarding my solution, feel free to ask. :slight_smile:

3 Likes