New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Why does my part go to nowher near my camera?

Asked by 14 days ago

Hi (again)! I am trying to make a part follow where my camera is (if you don't know yet). It doesn't go anywhere near the camera and goes in one certain spot. Help! (there is no error)

local owner = game.Players.iiDkOffical
local head = Instance.new("Part")
head.Name = "Head"
head.Anchored = true
print("Made Part")
local group = Instance.new("Model")
group.Name = "Unknown"
group.Parent = game:GetService("Workspace")
head.Parent = group
local humanoid = Instance.new("Humanoid")
humanoid.Parent = group
print("Made group")
head.Size = Vector3.new(1,1,1)
while true do
wait(0.25)
group.Name = owner.Name.." - Camera"
head.CFrame = game:GetService("Workspace").Camera.CFrame
end

2 answers

Log in to vote
1
Answered by
Feahren 3677 Moderation Voter Community Moderator
14 days ago
Edited 14 days ago

CurrentCamera is the actual Camera that is adjusted on the Player's screen, referencing 'Camera' will be setting the CFrame to a static position. Since the Camera is also rendered every Frame, we can tell the Part to match it's position at the same rate with RunService's .Heartbeat signal. This way we can make it follow the Camera smoothly.

local RunService = game:GetService("RunService")

RunService.Heartbeat:Connect(function()
    head.CFrame = workspace.CurrentCamera.CFrame
end)
0
nope, still doesn't follow the camera iiDkOffical 73 — 14d
0
Ensure this is a LocalScript, as I said before. Feahren 3677 — 14d
0
can you make it a script? iiDkOffical 73 — 14d
0
You'll still need a LocalScript to have this properly work. Use a RemoteFunction to call upon the Players Camera CFrame through the LocalScript, then the ServerScript to adjust the Part. Feahren 3677 — 14d
View all comments (2 more)
0
i knew that would be the answer iiDkOffical 73 — 14d
0
I tested my code above, conjoined with yours, it works perfectly fine, but I'm not necessarily sure why you want this to happen? It will constantly be interrupting the Camera's FOV causing it to push forward. If you want something to float above the Characters head? Then you can simply weld a part to it. Feahren 3677 — 14d
Ad
Log in to vote
1
Answered by
Nanomatics 1107 Moderation Voter
14 days ago
Edited 14 days ago

Just made the script a bit neater, this should work

--- put this in a localscript under StartPlayerScripts which is under StarterPlayer
local camera = workspace.CurrentCamera
local part

wait(3) -- just to make sure everything loaded

game["Run Service"].Heartbeat:Connect(function()
    if not part then
        local player = game.Players.LocalPlayer
        local char = player.Character
        part = Instance.new("Part")
        part.Name = "CAMERAPART"
        part.Anchored = true
        part.Parent = char
        part.CFrame = camera.CFrame
    end
    part.CFrame = camera.CFrame
end)

Hope I helped, if you have any questions please let me know

Answer this question