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)
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
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
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.
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.