I am trying to make a script that launches a colored block from a held tool in the direction you click your mouse, but I can't get it to work. It does not work in server mode, and in studio mode it causes the bullet to always fly in the same direction, no matter where you point your mouse or how you turn your body.
In a normal script I have
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)
This script works just fine in studio mode, but spawns the bullet in the center of the map in server mode.
In a local script I have
local tool = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()
function pew()
wait (.001)
local arrow = script.Parent.needle
arrow.CFrame = CFrame.new(tool.Handle.Position, mouse.Hit.p)
end
tool.Activated:connect(pew)
This is the script to give the spawned bullet it's direction. It does not work in server mode, and only changes which way the bullet faces in studio mode. Almost what I want, but without the momentum in the correct direction it's useless.
I know there is a thing you can turn off that might help with making it work better in server mode, but I don't know what it's called or how to find it. I am not really sure what to do about the bullet shooty direction though.
What can I do to fix this?

1 comment
It might be a loading issue, try adding a waitforchild or a "nil" checker