Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I attach the Camera to a Part?

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??

1 comment

0

Casual comment, forgot to mention the Part I want to attach it to is called Cheese

1 answer

✓ Accepted answer

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!

3 comments

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?

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).

0

It worked! :)

This discussion is preserved as it was. New answers, comments, and votes are closed.