I want to be able to allow players to aim in first person with the direction they are looking, but I don't know where to start. How could I integrate something like that?

This is my current script if it helps: (Script)

RepStorage = game.ReplicatedStorage
Event = RepStorage.Items.FlashLightEvent
Tool = script.Parent
FlashlightMesh = Tool.FlashlightMesh
SpotLight = FlashlightMesh.SpotLight

Event.OnServerEvent:Connect(function(Player,On)
	print("Detected")
	if On == false then
		print("Flashlight is off")
		SpotLight.Enabled = true
	elseif On == true then
		print("Flashlight is on")
		SpotLight.Enabled = false
	end
end)

(Local Script)

RepStorage = game.ReplicatedStorage
Event = RepStorage.Items.FlashLightEvent
Tool = script.Parent
FlashlightMesh = Tool.FlashlightMesh
SpotLight = FlashlightMesh.SpotLight
IdleAnim = script:WaitForChild('Idle')
Ambience = script.Parent.FLAmbient
FogEnding = script.Parent.FLFogEnd
On = false

Tool.Equipped:connect(function()
	local Humanoid = Tool.Parent:WaitForChild('Humanoid')
	IdleAnimLoaded = Humanoid:LoadAnimation(IdleAnim)
	equipped = true
	IdleAnimLoaded:Play()
end)

Tool.Activated:connect(function()
	print(Tool.Name.. " Activated")
	local LightingControl = Tool.Parent:WaitForChild('LightingControl')
	if On == false then
		Event:FireServer(false)
--		SpotLight.Enabled = true
		local Character = Tool.Parent
		LightingControl = Character:WaitForChild('LightingControl')
		LightingControl.Ambient.Value = LightingControl.Ambient.Value + Ambience.Value
		LightingControl.FogEnd.Value = LightingControl.FogEnd.Value + FogEnding.Value
		On = true
		print("1B:")
	elseif On == true then
		Event:FireServer(true)
--		SpotLight.Enabled = false
		local Character = Tool.Parent
		local LightingControl = Character:WaitForChild('LightingControl')
		LightingControl.Ambient.Value = LightingControl.Ambient.Value - Ambience.Value
		LightingControl.FogEnd.Value = LightingControl.FogEnd.Value - FogEnding.Value
		print("2B:")
		On = false
	end
end)

Tool.Unequipped:connect(function()
	print("Unequiped")
	equipped = false
	IdleAnimLoaded:Stop()
	local Character = Tool.Parent.Parent.Character
	local LightingControl = Character:WaitForChild('LightingControl')
	if On == true then
		Event:FireServer(true)
--		SpotLight.Enabled = false
		local LightingControl = Character:WaitForChild('LightingControl')
		LightingControl.Ambient.Value = LightingControl.Ambient.Value - Ambience.Value
		LightingControl.FogEnd.Value = LightingControl.FogEnd.Value - FogEnding.Value
		print("2B:")
		On = false
	end
end)

6 comments

0

just lerp the sight object to the camera's CFrame

0

Mouse.Hit is a good function for detecting where the player is looking, so when they click just fetch where their mouse hits, and cast a ray to that position, which would be the bullet to your FPS gun. Here's an article on mouse hits: https://developer.roblox.com/api-reference/property/Mouse/Hit Here's an article on raycasting: https://developer.roblox.com/articles/Raycasting

0

^ Their mouse will be in the center of their screen if you force their zoom all the way in, you could also just raycast out of the gun barrel and base your animations on pointing the gun barrel always forwards in the center where their crosshair should be

0

i don't really understand the question is but you mean like you want your character face in to your mouse

0

thats not english

0

@TheluaBanana What's the sight object?