#How come I can't access / change a player's camera mode in a local script?

1 messages · Page 1 of 1 (latest)

still trench
#

I'm just doing a test where when you click on a ClickDetector, your camera gets set into first person. When I click on it, nothing happens. Does it have something to do with the fact that it's a local script, or that it's parented to a ClickDetector in the workspace?

local players = game:GetService("Players");
local l_player = players.LocalPlayer;
local detector = script.Parent;

detector.MouseClick:Connect(function (player)
    l_player.CameraMode = Enum.CameraMode.LockFirstPerson;
end)
spring vergeBOT
#

studio** You are now Level 2! **studio

weak rampart
#

put it in starterplayerscripts

still trench
#

How would I access the ClickDetector thing?

#

From starterplayerscripts

weak rampart
#

local detector = workspace["Interact With This"].ClickDetector
short egret
#

workspace[“Default Stuff”][“Interact With This”].ClickDetector

still trench
#

no WaitForChild(...)?

weak rampart
still trench
#

This is still really new to me

weak rampart
short egret
still trench
weak rampart
#

in this case it would

still trench
#

What do you mean "not immediately inside of Workspace", ain't all objects that I put in, already in Workspace? Or do some get replicated later?

#

Cause I see WaitForChild("Something") and Workspace["Something"] often and i cant tell when to use which

weak rampart
#

i mean you can use either one really

#

but waitforchild can return errors

still trench
#

Ok so if I want to reference that "Interact With This" part, since it's in the Workspace, it don't matter?

weak rampart
#

it should be fine yeah. if you wanna be extra safe using waitforchild is fine. but its generally a bit uneccesary

still trench
#

One last question that I don't know how I forgot to ask : why can't local scripts be in Workspace?

weak rampart
spring vergeBOT
#

studio** You are now Level 15! **studio

still trench
weak rampart
#

there may be certain instances where local scripts run in workspace but ive never used it nor would i ever

still trench
#

okay

#

let me try some stuff and see if anything changes

weak rampart
#

also

#

you dont need semi colons

#

im not sure why your using them like that

#

but its uneccesary

still trench
#

force of habit from other programming languages

weak rampart
#

fair

#

its not needed in lua though

#

and it helps us read code especially when its longer

still trench
#

Alright

weak rampart
#

let me know if you need anything else

still trench
#
local players = game:GetService("Players")
local l_player = players.LocalPlayer
local detector = game:GetService("Workspace")["Interact With This"]

detector.MouseClick:Connect(function (player)
    l_player.CameraMode = Enum.CameraMode.LockFirstPerson
end)

I tried this, (apart from the fact that "Interact With This" isn't a ClickDetector), it tells me: 13:42:56.252 Interact With This is not a valid member of Workspace "Workspace" - Client - SetFP:3.

weak rampart
#

ah

#

try this

#

local detector = game:GetService("Workspace"):WaitForChild("Interact With This")

still trench
#

"Interact With This" aint a ClickDetector

#

But whatevr

weak rampart
#

oh lol

still trench
#

Voila

weak rampart
#

i didnt realise

still trench
#
local players = game:GetService("Players")
local l_player = players.LocalPlayer
local click_part = game:GetService("Workspace"):WaitForChild("Interact With This")
local detector = click_part:WaitForChild("ClickDetector")

detector.MouseClick:Connect(function (player)
    l_player.CameraMode = Enum.CameraMode.LockFirstPerson
end)
#

Now it's good

spring vergeBOT
#

studio** You are now Level 3! **studio

weak rampart
#

i mean you could just make it a single variable but fair enough

#

i didnt read that it wasnt a click detector

#

my fault

still trench
#

nah you're good