I need to aim a tool towards where the player clicks.
I have this script here in local
local tool = script.Parent local mouse = game.Players.LocalPlayer:GetMouse() function pew() wait (.01) local arrow = script.Parent.needle arrow.CFrame = CFrame.new(tool.Handle.Position, mouse.Hit.p) --like this, where the tool does something in the direction of your mouse click end tool.Activated:connect(pew)
There is a script in server which does the rest but i'm certain it works fine, but i'll provide it anyways.
local tool = script.Parent local bullet = game.ReplicatedStorage.bullets.needle local sound = tool.Sound function pew() sound:Play() local arrow = bullet:clone() arrow.Parent = tool game:GetService("Debris"):AddItem(arrow, .22) local v = Instance.new ("BodyVelocity", arrow) v.velocity = arrow.CFrame.lookVector *90 v.maxForce = Vector3.new(math.huge, math.huge, math.huge) tool.ManualActivationOnly = true wait (.3) tool.ManualActivationOnly = false end tool.Activated:connect(pew)
But it only works in studio because of the whole localscript interacting with server objects thing.
Is there a way I could aim the tool using a server script?
I could probably turn off filtering to make it work, but I would like to keep that on since it helps with learning to script good.
You shouldn't
All input should be handled locally. Clients expect immediate feedback when they give an input, and in this case they expect the movement of their mouse to be met with a visual feedback of the aiming. If this happens with the server, you're going to be met with lag. And people hate lag.
Just tell the server, but handle it locally.
It is possible ***But I would NOT recommend it as it would cause tremendous lag. ***
To fix your problem put the entire script within the tool itself. Aimdown-site would be a different script(just for neatness)