I am attempting to make it so when you are in a helicopter, you can press the L key, a spotlight will enable, and it will highlight over where your mouse is.
However, this is inaccurate, and just not working well at all, as you can see in this video: https://youtu.be/ZMMf3Twu1kY
The code for this is attached:
Client
local function onRenderStep()
if spotlightOn then
local success,errMsg = pcall(function()
if mouse.Target.CanCollide == false then return end
local mousePos = game:GetService('UserInputService'):GetMouseLocation()
local unitRay = workspace.CurrentCamera:ScreenPointToRay(mousePos.X,mousePos.Y)
local raycastResult = workspace:Raycast(unitRay.Origin,unitRay.Direction*800)
game:GetService('ReplicatedStorage').HelicopterEvents.SpotlightEvent:FireServer('move',raycastResult.Position)
end)
end
end
game:GetService('RunService').RenderStepped:Connect(onRenderStep)
Server
HelicopterEvents.SpotlightEvent.OnServerEvent:Connect(function(plr,req,pos)
if req == 'disable' then
script.Parent.Parent.BodyKit.Spotlight.Vidro.Beam.Enabled = false
script.Parent.Parent.BodyKit.Spotlight.Vidro.SpotLight.Enabled = false
end
if req == 'move' then
script.Parent.Parent.BodyKit.Spotlight.Part.Attachment.Position = pos
end
end)
Any help is appreciated