Uhm… no not quite. You need to add a :WaitForChild()
to the camera part and you aren’t assigning it here.
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 = workspace.CurrentCamera
local cameraPart
local absoluteSize, canvasSize, Inc = 0, 0, 0
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 = script.Parent:WaitForChild("CameraPart")
if cameraPart then
cameraPart.CFrame = camera.CFrame
end
end
???
Put the local script parented to startercharacterscripts and access the frame, camera and what not from there. Also get rid of the events because you won’t need them if your local script is in startercharacterscripts and they won’t work.
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 = workspace.CurrentCamera
local cameraPart = workspace:WaitForChild("CameraPart") -- *sigh*
local absoluteSize, canvasSize, Inc = 0, 0, 0
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 = script.Parent:WaitForChild("CameraPart") not here make sure the script is in the screen gui and not somewhere else.
if cameraPart then
cameraPart.CFrame = camera.CFrame
end
end
Wait a minute neither will any of your playeradded events because the script would only run after the player has been added. Unless it’s somehow working to which I say you’re a demon.
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 = workspace.CurrentCamera
local cameraPart = workspace:WaitForChild("CameraPart")
local absoluteSize, canvasSize, Inc = 0, 0, 0
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)
This works, but it doesn’t work when I die . Also I have done this on a separate LocalScript under the the ScreenGui like what @awry_y said.
cameraPart = script.Parent:WaitForChild("CameraPart")
May I ask why you need a cameraPart for a compass anyway? Are you trying to get it’s orientation? If so then there is a simpler method to do:
local _,orientationY = camera.CFrame:ToOrientation()
orientationY = math.deg(orientationY)
print(orientationY) -- would print out the cameras Y orientation without using a part.
its cuz u still have these events, none of these events are gonna fire even on your original script parented to the frame, or in startercharacterscripts.
local function moveWithOrientation()
local _, orientationY = camera.CFrame:ToOrientation()
orientationY = math.deg(orientationY)
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
I forgot this was still added in
In this script you are using cameraPart.Orientation.Y. So I thought you weren’t using ToOrientation. And you just added that because there isn’t even a single refrence to it in any of the previous scripts.
Orrrr I am just taking this stupidly and you are asking that if you did it correct. You did it correct alright… You didn’t provide any context okay!
I was asking if I did it correct, but for some reason doing that just completely breaks the compass
So did you get rid of the events and saw if it worked?
I got rid of it, since it did nothing. But after dying the compass still doesn’t work
And resetonspawn is set to true right
Probably because of the deg
variable. You can fix this like so:
local deg = orientationY < 0 and orientationY + 360 or orientationY
I did this because CFrame returns an angle from -180 to 180 while we need one from 0 to 360.
Yeah it’s been on this whole time.
local function moveWithOrientation()
local _, orientationY = camera.CFrame:ToOrientation()
orientationY = math.deg(orientationY)
local deg = orientationY < 0 and orientationY + 360 or orientationY
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
It breaks the whole compass
Well u should turn it to false maybe for the startercharacterscripts local script.
If I move the script somewhere else other than the ScrollingFrame it’s in it will break