Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I attach the Camera to a Part?

Asked by 9 years ago

So, I would like to Attach the Camera to a Part. I've gotten a few suggestions and I have no idea where to begin anymore and the Roblox Wiki isn't helping me. How do I do this?

What I have so far:

function player()

repeat wait() until game.Workspace.CurrentCamera

local cam = game.Workspace.CurrentCamera

cam.CameraSubject = game.Workspace.Cheese

cam.CameraType = ("Attach")

cam.FieldOfView = 50

end

game.Players.PlayerAdded:connect(player)

It is a LocalScript in StarterGui, but now I know that the PlayerAdded event does not work in a LocalScript. What do I do??

0
Casual comment, forgot to mention the Part I want to attach it to is called Cheese bookerjohnson 30 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

Use two scripts to get around this problem, a SERVER script that uses the PlayerAdded event to insert the LocalScript into StarterGui, and a LOCALscript that actually contains the code. The Localscript should be a child of the server script.

First, the server script:

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        script.LocalScript:clone().Parent = character --change this to redirect to the player's StarterGui
    end)
end)

This inserts the Localscript into the Player. Now you can put your code into the Localscript. When a Player spawns, the server script will trigger and put the Localscript in the Player, which will let the Localscript run. I hope this helps!

0
Okay, I can't believe I missed that. Thank you so much! One last question, I know what to put into the LocalScript now but how do I redirect to the player's StarterGui with ruining the connection of character? bookerjohnson 30 — 9y
0
I'm glad you thought my answer was helpful! You can accept my answer and upvote if you'd like to. Now regarding your question, I'm not sure. I've never had the need to redirect to PlayerGui or StarterGui because I always use the Player's model. I haven't tested this out, but try game.Players:GetPlayerFromCharacter(character). IcyArticunoX 355 — 9y
0
It worked! :) bookerjohnson 30 — 9y
Ad

Answer this question