I know i've been making a lot of threads on this lately, but this is really hard.

I need the tool to shoot a brick in the direction the player clicks/looks, however that seems to be nigh-impossible without a localscript, but localscripts seem ruin the tool in multiplayer mode.

local tool = script.Parent
local bullet = game.ReplicatedStorage.bullets.needle 
local sound = tool.Sound

function onActivated(vTarget)
	local player = tool.Parent
	-- local humanoid = player.Humanoid -- i don't remember why i defined this
	--local plr = game.Players.player
	local arrow = bullet:clone() 
	
	--
	local vHandle = tool.Handle--this whole section i jammed into here from 
	local direction = vTarget - vHandle.Position --some other script hoping it would
	direction = computeDirection(direction)--work, but it doesn't
	local pos = vHandle.Position + (direction * 10.0)
	arrow.CFrame = CFrame.new(pos,  pos + direction) * CFrame.Angles(math.pi/2, 0, 0)
	--Players.Player.Backpack.Needle Punch.Script:13: bad argument #1 to '?' (Vector3 expected, got nil)
	-- but vector3 isn't a valid member of part
	
sound:Play() --noise

local arrow = bullet:clone() 
arrow.Parent = tool 
game:GetService("Debris"):AddItem(arrow, .2)--time before the bullet expires


tool.ManualActivationOnly = true
wait (.3)
tool.ManualActivationOnly = false --tool debounce
end


script.Parent.Activated:connect(onActivated)

I also have

local tool = script.Parent
local bullet = game.ReplicatedStorage.bullets.needle 
local sound = tool.Sound

function onActivated()
	local player = script.Parent -- i don't think this works
	local mouse = player:GetMouse() --this doesn't work
sound:Play()
local arrow = bullet:clone() 
arrow.Parent = tool 
game:GetService("Debris"):AddItem(arrow, .4)

arrow.CFrame = CFrame.new(tool.Handle.Position, mouse.Hit.p)
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 (.5)
tool.ManualActivationOnly = false
end



script.Parent.Activated:connect(onActivated)

and

Tool = script.Parent
bullet = game.ReplicatedStorage.bullets.needle
function fire(v)
	local vCharacter = Tool.Parent
	local vPlayer = game.Players:playerFromCharacter(vCharacter)
	Tool.Parent.Torso["Right Shoulder"].DesiredAngle = 3
	local missile = bullet:Clone()
	local v1 = Tool.Bolt.CFrame.lookVector.unit --stops here
	local v2 = v.unit
	local dot = (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z)
	local ang = math.acos(dot)

	if (ang < 3.14 / 8) then

	missile.CFrame = Tool.Bolt.CFrame + (v * 8)
	missile.Transparency = 0
	missile.Velocity =  v * 100
	missile.Name = "CrossbowBolt"
	missile.Elasticity = 0
	local force = Instance.new("BodyForce")
	force.force = Vector3.new(0,150,0)
	force.Parent = missile
	missile.BodyGyro.cframe = CFrame.new(Vector3.new(0,0,0), -Tool.Bolt.CFrame.lookVector.unit)
	missile.BodyGyro.maxTorque = Vector3.new(5e5,5e5,5e5)
	end
end


Tool.Enabled = true

function onActivated()
	if not Tool.Enabled then
		return
	end
	Tool.Enabled = false
	local character = Tool.Parent;
	local humanoid = character.Humanoid
	local targetPos = humanoid.TargetPoint
	local lookAt = (targetPos - character.Head.Position).unit
	Tool.Sound:Play()
	fire(lookAt) --also stops here
	wait(2)
	Tool.Enabled = true
end



script.Parent.Activated:connect(onActivated)

which is a slightly modified script from free models, because i've about given up at this point

all of the above scripts are in server scripts

How do I fix this?

or even better, how do i get something to shoot where the player clicks using no local scripts? Possibly using lookvectors or whatever they're called, where the bullet goes where the player is looking?

I don't care about lag for the time being, as long as it works in server.

2 comments

0

you should either be using all local scripts, or local scripts + remote events/functions with FE. This is because tools are local and mouses are local, so there's no need to use the server for it.

0

but if i use local the bullet will either get no momentum , spawn in the middle of the map, or not be able to interact with humanoids