Trying to get an in game teleport gui to work, having trouble

Hey guys,

Im working on a game which has several different areas on the map, and ive made some gui buttons to help people get around.

The script I came up with works in studio, but not online servers. Can anyone help me out? I have a value setting with the name of the brick they teleport to.

local location = game.Workspace.TP[script.Parent.TeleportName.Value] -- Location

local player = game.Players.LocalPlayer -- Player

script.Parent.MouseButton1Down:connect(function() -- click

    player.Character:MoveTo(location.Position) -- teleport

end)
2 Likes

Local instances inside PlayerGui might not have loaded yet, I don’t know if you have any errors but script.Parent.TeleportName.Value might not have loaded yet, I suggest using WaitForChild

1 Like

As Classified mentioned it’s probably because the value hasn’t loaded yet. Although, you could make some changes to prevent future errors

local Player = game:GetService(‘Players’).LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Location = workspace.TP[script.Parent:WaitForChild(‘TeleportName’).Value]

script.Parent.MouseButton1Click:Connect(function()
if Character then
Character:MoveTo(Location.Position)
end
end)

Also @Chthxnian , MoveTo is preferable as it works for both rig types and runs a collision check

2 Likes

I would not recommend using @Chthxnian 's method, only because you should use a remote event for this. I also would set the CFrame of your character’s HumanoidRootPart so it works with R6 and R15 without having to do an extra check.

1 Like

Thanks guys, that seems to have solved the issue!

Feel free to check out what im working on if you want to.

2 Likes

Character movement replicates; you don’t need an event

1 Like

That works too I guess. Haha.

1 Like

Yeah. I was thinking that, it’s almost as useless as using a remote event to set walk speed. But I’d still set CFrame of the HumanoidRootPart for teleportation.

1 Like

Okay. I’m primarily a builder, so I just wrote a simple script and I wasn’t really thinking about that, but thanks for letting me know.

1 Like

No problem.

1 Like

MoveTo uses the Models primary part. Using the HRP directly offers no benefit

1 Like

Your code didnt work actually, im not sure why it isnt working.

1 Like

Check output :eyes:

1 Like

[LocalScript:1: unexpected symbol near ‘�’]

1 Like

The quotation marks are the wrong character lol.

1 Like

Oh, yeah, I typed that on my phone - it has a messed up keyboard. Just replace the quotation marks

I’ve replaced them in the post too :+1:

1 Like

haha I noticed as soon as I checked output, thank you though for the solution! This helped alot

1 Like

Interesting, I generally use MoveTo with non-player objects, such as NPC walking, didn’t know it had that behavior when working with player objects :thinking:

1 Like

MoveTo on the humanoid instance makes it walk, MoveTo on the model just teleport with collision detection

1 Like

Just a quick note about you’re formatting, it should be three apostrophes (’)

1 Like