Ive tried to make a thing connecting a light to the camera for a flashlight but its not working (i need it attached to the camera because i have the camera attached to parts)
this is the script i have that should attach it (i took it from a open source plugin that attaches a light to your camera):
local Camera = workspace.CurrentCamera
local part = script.Parent
local spotlight = part.SpotLight
game:GetService("RunService").Heartbeat:Connect(function()
part.CFrame = Camera.CFrame
end)
Just so you know, this can work for either Server and Client, It ultimately Depends on your usage of the following code
If you plan to have invisible to all Players while maintaining visibility for your Local Client, you would use a LocalScript for this which can easily be accessed with the following: StarterPlayerScripts, StarterCharacterScripts, ReplicatedStorage, ReplicatedFirst, StarterGui
And in some cases, you are able to put a LocalScript within the workspace and have it fully working by using a Regular Script and setting its RunContext to Client, which has the Script run as a LocalScript, but unlike regular LocalScripts, it can basically run within the workspace
You can try doing it with StarterCharacterScripts and use either Stepped(PreSimulation) or Heartbeat(PostSimulation) for this as RenderStepped(PreRender) only works on the Client.
However, If you want to Simplify the use, You can easily just Attach a Light to the Player, more specifically, on their Head which is way faster and more resourceful.
Instances can only be Parented to the Camera, but not Attached to it, you would need to use CFrame to have this effect.
i think you may be looking for Enabled, unless you have a Child named On
Sending Data from Client to Server can be done with RemoteEvents, However this may not be ideal.
local Camera = workspace.CurrentCamera
local part = script.Parent
local spotlight = part.SpotLight
Camera.CameraType = Enum.CameraType.Scriptable
game:GetService("RunService").Heartbeat:Connect(function()
part.CFrame = Camera.CFrame
end)
Make sure you change the CameraType to Scriptable if you want to play with the camera