You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
- I want to teleport the player’s character to a certain spot.
- What is the issue? Include screenshots / videos if possible!
- Instead of teleporting the entire character, it just teleports the HumanoidRootPart, and that completely Destroys the character.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
-
No, I didn’t.
-
At first, I used CFrame, but the (local)script responded with an error saying:
Players.TheFairFellow.PlayerGui.ScreenGui.ButtonHandler:97: invalid argument #2 (Vector3 expected, got CFrame) -
Then I switched to Vector3 and Position instead of CFrame and when I tested it, then it gave me this weird state.
Here’s my script (This is a LocalScript inside of a ScreenGui)
-- Variables
local player = game.Players.LocalPlayer
local humRootPart = player.Character:WaitForChild("HumanoidRootPart")
local cam = workspace.CurrentCamera
local cam1 = workspace.CamPart1
local cam2 = workspace.CamPart2
local cam3 = workspace.CamPart3
local button = script.Parent.MainMenu
local button2 = script.Parent.Shop
local play = script.Parent.Play
local button3 = script.Parent.ShotgunMode
local frame = script.Parent.WhiteScreen
local switchedToCam2 = false
local switchedToCam1 = false
local switchedToCam3 = false
-- Tweening
local TweenS = game:GetService("TweenService")
local info = TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local screenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local cam1Tween = TweenS:Create(cam, info, {CFrame = cam1.CFrame})
local cam2Tween = TweenS:Create(cam, info, {CFrame = cam2.CFrame})
local cam3Tween = TweenS:Create(cam, info, {CFrame = cam3.CFrame})
local frameTweenIn = TweenS:Create(frame, screenInfo, {Transparency = 0})
local frameTweenOut = TweenS:Create(frame, screenInfo, {Transparency = 1})
-- Actual code
wait(0.001)
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = cam1.CFrame
player.Character.Humanoid.WalkSpeed = 0
player.Character.Humanoid.UseJumpPower = true
player.Character.Humanoid.JumpPower = 0
button.MouseButton1Click:Connect(function()
if not switchedToCam1 then
wait(0.1)
cam1Tween:Play()
switchedToCam1 = true
switchedToCam2 = false
switchedToCam3 = false
play.Text = "Play"
end
end)
button2.MouseButton1Click:Connect(function()
if not switchedToCam2 then
wait(0.1)
cam2Tween:Play()
switchedToCam2 = true
switchedToCam1 = false
switchedToCam3 = false
play.Text = "Spawn"
end
end)
button3.MouseButton1Click:Connect(function()
if not switchedToCam3 then
wait(0.1)
cam3Tween:Play()
switchedToCam3 = true
switchedToCam2 = false
switchedToCam1 = false
play.Text = "Play"
end
end)
play.MouseButton1Click:Connect(function()
local ShopSpawn = workspace.ShopSpawn
local MainSpawn = workspace.MainSpawn
local ShotgunSpawn = workspace.ShotgunSpawn
frameTweenIn:Play()
wait(3)
frameTweenOut:Play()
wait(0.5)
script.Parent.Enabled = false
player.Character.Humanoid.WalkSpeed = 16
player.Character.Humanoid.JumpPower = 50
cam.CameraType = Enum.CameraType.Custom
if switchedToCam1 then
humRootPart.Position = MainSpawn.Position + Vector3.new(0, 3, 0)
elseif switchedToCam2 then
humRootPart.Position = ShopSpawn.Position + Vector3.new(0, 3, 0)
elseif switchedToCam3 then
humRootPart.Position = ShotgunSpawn.Position + Vector3.new(0, 3, 0)
end
end)
This actually happened to me before. (That also happened in a LocalScript with 2 buttons, kinda similar to this situation) Have I done something wrong, or this is a studio bug?
Yes, I know that my username doesn’t match with the studio character’s username, that’s because it’s an alt.
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.