LocalScript works on studio but not when I play the game

local player = game.Players.LocalPlayer
-- Wait for the character to load
local character = player.Character or player.CharacterAdded:Wait()
print("added")

local car = workspace:WaitForChild("StarterCharacter")
local cam = workspace.CurrentCamera -- Get the current camera

-- Set camera properties
cam.CameraType = Enum.CameraType.Custom
cam.CameraSubject = car-- Set the camera to follow the car

print("Camera set up completed")

You can just do a compound statement on that to check. Note that StarterCharacter is always named when you place it in workspace, according to the player name(display?), usually.

1 Like

not working :grimacing: :grimacing: :grimacing: :grimacing: :grimacing: :grimacing: :grimacing: :grimacing: :grimacing:

aaaaaaaaaaaaaaaaaaaa

if printing something on the first line doesn’t work, then changing a line of code that runs AFTER the first line won’t change anything

1 Like

the print works on studio but not in the game

Just putting up blanket statements like that isn’t helping either of us. You have to elaborate why it is not working and what you are actually expecting. :unamused:

It should work if it is correctly parented and is actually not on a disabled state.

1 Like

i think this is just device progress speed problem as mine worked on both try to wait more like 3-5 second

1 Like

If a script runs in test but not on the server it’s because it’s handled incorrectly.

Your computer runs as the server in studio test mode.
If you run a localscript in Studio it’ll perform and output as both local and server.

Try switching it to a Script instead.

1 Like

I tried it with more than 1 device all of them have the same problem.

1 Like

yeaaaaa try @Scottifly method that might work

2 Likes

woah that worked!!! can u explain to me that again so I can know exactly what was the problem.

1 Like

ty all for your help guys, sorry for wasting your times :sweat_smile:

1 Like

I’m probably wrong with some details of this information, so if someone has a better explanation please share it.

So when you play a game, Roblox runs the game on their server.
Your computer (the client) receives and sends information about your inputs and gameplay dynamics.

LocalScripts run on the client. Scripts have access to the server depending on where they are located in your game.

When you test the game in Studio Roblox doesn’t open a server for you. Your computer acts as both the client and the server. LocalScripts will act like server scripts in this case.

It helps when troubleshooting because it’s a pretty clear indicator of what’s happening. :grinning:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.