This compass script doesn’t work after dying.
local frame = script.Parent
local n, e, s, w, ne, nw, se, sw, nw2, n2, ne2 = frame.N, frame.E, frame.S, frame.W, frame.NE, frame.NW, frame.SE, frame.SW, frame.NW2, frame.N2, frame.NE2
local directions = {nw, n, ne, e, se, s, sw, w, nw2, n2, ne2}
local camera, cameraPart = workspace.CurrentCamera, workspace.CameraPart
local absoluteSize, canvasSize, Inc = 0, 0, 0
if not cameraPart or not cameraPart:IsDescendantOf(workspace) then
-- Find or recreate cameraPart here
return
end
local function updateTextColor(textLabel, condition)
if condition then
textLabel.TextColor3 = Color3.fromRGB(171, 142, 98)
else
textLabel.TextColor3 = Color3.fromRGB(171, 142, 98)
end
end
local function partToCamera()
cameraPart.CFrame = camera.CFrame
end
local function tickMarks(position, thickness)
local mark = Instance.new("Frame")
mark.AnchorPoint = Vector2.new(1, 0)
mark.Position = UDim2.new(0, position, 0, 0)
mark.BorderSizePixel = 0
mark.BackgroundColor3 = Color3.fromRGB(171, 142, 98)
mark.Name = "TickMark"
mark.Parent = frame
if thickness == "thicker" then mark.Size = UDim2.new(0, 3, -0.1, 1) end
if thickness == "thick" then mark.Size = UDim2.new(0, 2, -0.1, 1) end
if thickness == "thin" then mark.Size = UDim2.new(0, 1, 0.5, 1) end
return mark
end
local function removeTickMarks()
for i, v in pairs(frame:GetChildren()) do
if v.Name == "TickMark" then v:Destroy() end
end
end
local function updateTickMarks()
for i, v in pairs(frame:GetChildren()) do
if v:IsA("TextLabel") then
local pxPos = v.Position.X.Offset
if #v.Text == 1 then tickMarks(pxPos, "thicker") end -- N, W, S, E
if #v.Text == 2 then tickMarks(pxPos, "thick") end -- Others
end
end
for j = 22.5, 427.5, 45 do tickMarks(j * Inc, "thin") end
--for k = 11.25, 416.25, 45 do tickMarks(k * Inc, "thin") end
--for l = 33.75, 438.75, 45 do tickMarks(l * Inc, "thin") end
end
local function positionElements()
absoluteSize = frame.AbsoluteSize.X
canvasSize = absoluteSize * 5
Inc = (absoluteSize * 4) / 360
for i, dir in ipairs(directions) do
dir.Position = UDim2.new(0, 45 * (i - 1) * Inc, 0.5, 0)
end
removeTickMarks()
updateTickMarks()
frame.CanvasSize = UDim2.new(0, canvasSize, 0, 0)
end
local function moveWithOrientation()
local orientationY = cameraPart.Orientation.Y % 360
local deg = (360 - orientationY) % 360
local inc = (absoluteSize * 4) / 360
frame.CanvasPosition = Vector2.new(deg * inc, 0)
positionElements()
local centerPos = frame.AbsoluteSize.X / 2
for i, dir in ipairs(directions) do
local labelPos = (45 * (i - 1) * Inc) - frame.CanvasPosition.X % canvasSize
local distanceToCenter = math.abs(centerPos - labelPos)
if distanceToCenter < 10 or distanceToCenter > canvasSize - 10 then
dir.TextColor3 = Color3.fromRGB(255, 255, 255)
else
dir.TextColor3 = Color3.fromRGB(171, 142, 98)
end
end
end
local Players = game:GetService("Players")
local function onCharacterAdded(character)
cameraPart = character:WaitForChild("CameraPart") -- Adjust based on actual child
-- Re-setup any connections or states needed
partToCamera()
moveWithOrientation()
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)
moveWithOrientation()
partToCamera()
cameraPart:GetPropertyChangedSignal("Orientation"):Connect(moveWithOrientation)
frame:GetPropertyChangedSignal("AbsoluteSize"):Connect(positionElements)
camera:GetPropertyChangedSignal("CFrame"):Connect(partToCamera)