So, I’ve been trying to edit this script to work with a part and to move the HumanoidRootPart via CFrame to a part and then making sure the camera faces the right way. Is there a way I can make this script server sided and fix it? Works if changed a little to work with a ScreenGUI and textbutton but doesn’t with a part.
Mostly, been having problems getting the character’s HumanoidRootPart and CFraming it to another part while changing the camera using a server sided script. If theres a way to do this without a server sided script and using a local script, it would also help.
Script:
Player = game:GetService("Players")
Dest = script.Parent.Destination
Teleporter = script.Parent.Teleporter
HasPressedTeleport = false
local Cam = workspace.CurrentCamera
Teleporter.Touched:connect(function(part)
if HasPressedTeleport == false then
local Character = Player.Character or Player.CharacterAdded:Wait()
local Character = part.Parent
if Character then
local HRP = Character:WaitForChild('HumanoidRootPart')
HRP.CFrame = Dest.CFrame
repeat
wait()
Cam.CameraType = Enum.CameraType.Attach
until Cam.CameraType == Enum.CameraType.Attach
repeat
wait()
Cam.CameraType = Enum.CameraType.Custom
until Cam.CameraType == Enum.CameraType.Custom
end
end
end)
Teleporter.Touched:connect(teleport)
Do local scripts even work in workspace? Or should I use a local script to detect if the character touches a part named Teleporter to go to the Destination?
No, LocalScripts don’t work in the workspace, but you can either check when the character’s touched like you said or reference the part that is in workspace from somewhere else. Just so you know, the wiki says where LocalScripts can run.
Yep, but you’d have to loop through each of the character’s parts and connect a function to all of their touched events. For example:
local function touchedThing(part)
-- touched event stuff here
end
for _, child in pairs(character:GetChildren()) do -- character would be defined somewhere else
if child:IsA("BasePart") then
child.Touched:Connect(touchedThing)
end
end
Not unless you’re using some kind of custom character; the default avatar touches stuff with its legs. You’d only have to set the CFrame of the HumanoidRootPart to teleport the character though.
They can use Humanoid.Touched, which will fire if any part of the character touches something. Much easier and more reliable than looping through the entire characters parts.
As for the main question, I would just use a LocalScript, located somewhere that it can be ran (StarterGui is fine, but I’d personally put it in StarterPlayerScripts)
You could improve on this method by using CollectionService to tag the teleported with (for example) a teleporter tag, and check if the basePart which was touched has the tag before teleporting.