I have rendered the entire map into a bird's-eye view image, and have it as an ImageButton. Here's my weak attempt at the question:
local Players = game:GetService('Players') local localPlayer = Players.LocalPlayer local UserInputService = game:GetService('UserInputService') local button = localPlayer.PlayerGui:WaitForChild('Gui').Map button .MouseButton1Click:Connect(function() local relativeMousePos = UserInputService:GetMouseLocation() - button.AbsolutePosition local pos = Vector3.new(relativeMousePos.X, 200, relativeMousePos.Y) print(pos) localPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(pos) end)
While it certainly does teleport, but neither does the scale or the position aligns with the actual map.
I have seen these posts:
DevForum: 2D positioning to 3D positioning
DevForum: How would I get the world position of a GUI properly?
DevForum: How to find the cursor position inside a gui object
However I cannot understand them well enough to combine and apply them to my situation.
Try using Mouse.Hit.Position
or UserInputService
and rays.
1. Mouse
--LocalScript in StarterPlayerScripts local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local RemoteEvent = game:GetService(“ReplicatedStorage”):WaitForChild(“TeleportClick”) --if you don’t have this RemoteEvent in the ReplicatedStorage, create one because it will cause an error Mouse.Button1Down:Connect(function() local position = Mouse.Hit.Position RemoteEvent:FireServer(position) end) --Script in ServerScriptService local RemoteEvent = game:GetService(“ReplicatedStorage”):WaitForChild(“TeleportClick”) --if you don’t have this RemoteEvent in the ReplicatedStorage, create one because it will cause an error RemoteEvent.OnServerEvent:Connect(function(player, MousePosition) local Character = player.Character or player.CharacterAdded:Wait() local Humanoid = Character:FindFirstChildOfClass(“Humanoid”) local Torso = Character:FindFirstChild(“Torso”) or character:FindFirstChild(“HumanoidRootPart”) if Character and Humanoid and Torso and Humanoid.Health > 0 then Torso.CFrame = CFrame.new(MousePosition) + Vector3.new(0, 3, 0) end end)
2. UserInputService
--LocalScript in StarterPlayerScripts local Player = game.Players.LocalPlayer local UserInputService = game:GetService(“UserInputService”) local RemoteEvent = game:GetService(“ReplicatedStorage”):WaitForChild(“TeleportClick”) --if you don’t have this RemoteEvent in the ReplicatedStorage, create one because it will cause an error UserInputService.InputBegan:Connect(function(input, gameProcessedEvent) if gameProcessedEvent then return end if (input.UserInputType == Enum.UserInputType.MouseButton1) or (input.UserInputType == Enum.UserInputType.Touch) then local MousePosition = UserInputService:GetMouseLocation() local camera = workspace.CurrentCamera local unitRay = camera:ScreenPointToRay(MousePosition.X, MousePosition.Y) RemoteEvent:FireServer(unitRay.Origin) end end) --Script in ServerScriptService local RemoteEvent = game:GetService(“ReplicatedStorage”):WaitForChild(“TeleportClick”) --if you don’t have this RemoteEvent in the ReplicatedStorage, create one because it will cause an error RemoteEvent.OnServerEvent:Connect(function(player, MousePosition) local Character = player.Character or player.CharacterAdded:Wait() local Humanoid = Character:FindFirstChildOfClass(“Humanoid”) local Torso = Character:FindFirstChild(“Torso”) or character:FindFirstChild(“HumanoidRootPart”) if Character and Humanoid and Torso and Humanoid.Health > 0 then Torso.CFrame = CFrame.new(MousePosition) + Vector3.new(0, 3, 0) end end)