Okay so I have been working on this code all day but for some reason the teleport script wont work, everything else works fine but when a click on the button and trigger the function it does not teleport me it just closes all the gui's (Which is should do but still it should also teleport).
the main script:
local character = game.Players.LocalPlayer.Character Start = script.Parent.StartButton CourseSelect = script.Parent.CourseSelect target = game.Workspace.Cam camera = workspace.CurrentCamera camera.CameraType = Enum.CameraType.Scriptable camera.CameraSubject = target angle = 0 go = 0 CourseSelect.Visible = false Num = 0 Course1 = script.Parent.CourseSelect.Course1 Course2 = script.Parent.CourseSelect.Course2 Course3 = script.Parent.CourseSelect.Course3 Course1.Visible = false Course2.Visible = false Course3.Visible = false -- Size X 400, Size Y 300 print("Started = false") function ClickedStart() CourseSelect.Visible = true Start.Visible = false for GuiSize = 1, 45 do if GuiSize <= 45 then CourseSelect.Size = CourseSelect.Size +UDim2.new(0.01, 0, 0.015, 0) Num = Num +1 print(Num) end wait() end Course1.Visible = true Course2.Visible = true Course3.Visible = true end function ClickedCourse1() Course1.Visible = false Course2.Visible = false Course3.Visible = false CourseSelect.Visible = false wait(3) character.CFrame = CFrame.new(game.Workspace.Course1Tele.Position + Vector3.new(0,3,0)) end Course1.MouseButton1Down:connect(ClickedCourse1) Start.MouseButton1Down:connect(ClickedStart)
Like I have said above, everything else works so if you have any suggestions please help. I should also add that this works fine in Solo mode but when I publish it to roblox that is when it wont teleport. Also I don't see anything bad appear in the output console so I'm clueless on whats going on.
If the character is nil, it's most likely because the script runs before the character is loaded. To fix this, either wait a few seconds before defining the variable, or do this:
repeat wait() until game.Players.LocalPlayer.Character --Waits until the character is not nil. local character = game.Players.LocalPlayer.Character
EDIT:
On line 43, you try to change the CFrame of the character. However, the character is a model. A model does not have a CFrame, only a brick does.
Solution: Use the MoveTo()
method on the character model, or change the CFrame of the character's torso.
So,
character:MoveTo(game.Workspace.Course1Tele.Position + Vector3.new(0,3,0))
Or,
character.Torso.CFrame = CFrame.new(game.Workspace.Course1Tele.Position + Vector3.new(0,3,0))
I've never really liked the MoveTo method, it's always given me problems and isn't as easy to manipulate as say just CFraming the model. Try this..
character.Torso.CFrame = CFrame.new(game.Workspace.Course1Tele.Position + Vector3.new(0,3,0)) --Add 3 to the y scale so they don't get stuck inside the part
Not that I even saw anything really wrong with either of those scripts, just this is another way that I know works.
I know this isn't a lot to help seeing as how I don't know what was wrong but just try this and hope it works, if not tell me.
-Goulstem