How can I make this run when a player touches a specific part

Hello!

I am currently trying to make a Teleport Service script. But it is running slow. So, I came up with an idea to make it when the players touch a specific part a countdown starts. And I was wondering. How can I make an if touched function that starts a countdown for the player that touched it? Thanks!

Use the Touched Event that is available on a BasePart (Includes Part, Union, etc…) and then send an event to the client via RemoteEvent telling them to start a Countdown. After you sent the event on the server, you can either put directly a wait(10) inside the Server Script or make the client tell the server the countdown is over so the Server can teleport them.

Can you add a script. I do not understand. Sorry if this sounds like I’m a bad scripter. I am new at developing and I am still learning to code.

“I’m a bad scripter” isn’t an excuse to not learn. Asking for scripts in general is against the rules. @SimplyData did a good job explaining what is needed to be done, now it’s your turn to try and construct the thing. Please learn the basics before attempting stuff you don’t have an idea on how to do!

1 Like

Alright, thanks for the reply. I will try to figure it out!

1 Like

Server (in ServerScriptService)

local Part = workspace.TouchMeToTeleport

Part.Touched:Connect(function(Hit)
	local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
	if Player then
		game.ReplicatedStorage.StartCountdown:FireClient(Player)
	end
end)

game.ReplicatedStorage.CountdownDone.OnServerEvent:Connect(function(Player)
	-- Teleport Player here
end)

Client (anywhere you can run a LocalScript)

game.ReplicatedStorage.StartCountdown.OnClientEvent:Connect(function()
	for i=10,0,-1 do
		local timer = i+1
		-- Do what you want with timer, it represents the time left
		wait(1)
	end
	game.ReplicatedStorage.CountdownDone:FireServer()
end)

You need to modify this example to your own needs, since as @starmaq said,

Developer Hub Articles you can use to learn more:

Found a solution, in the future I will try to find a solution in the developer hub or I will try to find a solution myself. I will post the solution in a minute…

Oh, never mind. It was the same thing.