So I've been trying to make a script that is able to teleport a player when they solve a certain riddle/puzzle. Once the player says the answer out loud near a part named gravestone they teleport to another place. I've had a lot of trouble with this and I just need a bit of help
COMMUNITY QUESTION
How to make a script that teleports a player to another place when you say a certain word?
2 answers
For these kinds of these things, you'll need the Chatted event along with TeleportService. The Chatted event fires whenever the player enters a message into the chat. You'll need a server script to manage these, since the server does teleport and kick.
This script would be in ServerScriptService,
Change RiddleAnswer to the text of your riddle answer, placeToTp to the place ID of where you want to teleport, and "workspace.Part" in line 16 to the directory of your Graveyard part, for example it can be in a folder in the workspace, so if it is, change it to that.
local RiddleAnswer = "TestAnswer"--Edit this to be your riddle answer with the quotation marks
local placeToTp = 5 --Change this to the place ID of where you want to teleport to
local function CheckDistance(plr,PartToCheck,Distance)
local char = plr.Character
local HRP = char:WaitForChild("HumanoidRootPart")
if (HRP.Position - PartToCheck.Position).Magnitude <= Distance then
return true
else
return false
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)--Whenever the player chats, with their message as the parameter value.
local Func = CheckDistance(plr,workspace.Part,15)--Change "workspace.Part" to the location in the Explorer of your Graveyard part. This checks if the player is in distance if the part
if Func == true then
print("Hi")
if msg == RiddleAnswer then
game:GetService("TeleportService"):Teleport(placeToTp,plr)
end
end
end)
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.
