Hello! I am working on a GPS system which has been delayed due to me not knowing the math for it. What I want to make is that whenever, and wherever the player clicks in the minimap, it makes a waypoint at that location in the real world. I’ve got some code:
local GPS_BUTTON = script.Parent;
local player = game:GetService("Players").LocalPlayer
local Mouse = player:GetMouse()
local location = script.Parent.Parent:WaitForChild("Location")
local UserInputService = game:GetService("UserInputService")
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local locations = {};
local Camera = game.Workspace.CurrentCamera
local origin = UDim2.fromScale(0.5, 0.5)
humanoid.Touched:Connect(function(hit)
if hit.Name == "GPS" then
hit:Destroy()
for index, location in ipairs(locations) do
location:Destroy()
end
locations = {}
end
end)
GPS_BUTTON.MouseButton1Click:Connect(function()
if game.Workspace:FindFirstChild("GPS") then return end
local relPos = Vector2.new(Mouse.X,Mouse.Y)-GPS_BUTTON.AbsolutePosition -- relative position in pixels
local scale = relPos/GPS_BUTTON.AbsoluteSize -- relative position in scale
scale = UDim2.new(scale.X, 0, scale.Y, 0)
local newLo = location:Clone()
table.insert(locations, newLo)
newLo.Visible = true
newLo.Position = scale
newLo.Parent = location.Parent
local anotherLo = newLo:Clone()
anotherLo.Visible = true
anotherLo.Size = UDim2.new(0.116, 0,0.111, 0)
anotherLo.Position = scale
anotherLo.Parent = GPS_BUTTON.Parent.Parent.Frame.Map
table.insert(locations, anotherLo)
local PART = Instance.new("Part")
local desiredWorldPosition = Vector3.new()
local relX = (newLo.AbsolutePosition.X - origin.X.Scale)
local absX = (game.Workspace.Terrain.Size.X * 0.5)
local relZ = (newLo.AbsolutePosition.Y - origin.Y.Scale)
local absZ = (game.Workspace.Terrain.Size.Z * 0.5)
desiredWorldPosition = Vector3.new(relX/absX, 5, relZ/absZ)
PART.Size = PART.Size + Vector3.new(0, 20, 0)
PART.Position = desiredWorldPosition -- Dunno
PART.Anchored = true
PART.Parent = game.Workspace
PART.CanCollide = false
PART.Transparency = 0.5
PART.Name = "GPS";
end)
But it always positions the part at 1 position no matter where I click in the minimap.
Stuck at this for a while now.
Any help that solves this will make my day. Thank you.