I've kinda re-written part of the code but if i got you correctly you want something to shoot from your player and head towards the mouse hit?
if so you need to change the script to the following:
LocalScript!
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:wait()
local Speed = 50
local Mouse = Player:GetMouse()
function GetBasePartFromRig(char,SubPart)
local humanoid = char:WaitForChild("Humanoid")
SubPart = SubPart == nil and "HumanoidRootPart" or SubPart
if(humanoid ~= nil) then
local Base = nil
Base = char:FindFirstChild(SubPart)
if(Base ~= nil) then
return Base
else
warn("Warning! SubPart of Character named "..tostring(SubPart).." has not been found! \n returning HumanoidRootPart as default!")
return char:WaitFirChild("HumanoidRootPart")
end
end
error("Error!: Humanoid is not a valid part inside "..tostring(char).." \n stopping script!")
end
local Base = GetBasePartFromRig(Char,"RightHand")
Mouse.Button1Down:connect(function()
local baconflake = (function()
local Part = Instance.new("Part",workspace)
for k,v in pairs(Enum.NormalId:GetEnumItems()) do
Part[v.Name.."Surface"] = Enum.SurfaceType.SmoothNoOutlines
end
Part.Size = Vector3.new(1,1,1)
Part.Shape = Enum.PartType.Ball
Part.Color = Color3.fromHSV(math.random(),1,1)
return Part
end)()
local aaa = Instance.new("BodyVelocity")
baconflake.Anchored = false
baconflake.CFrame = Base.CFrame
baconflake.Parent = workspace
aaa.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
aaa.Velocity = (Mouse.hit.Position - Base.CFrame.Position).unit * Speed
aaa.Parent = baconflake
end)
the script is working as is.i've included a small function that will return the HumanoidRootPart as default if the part you specify doesn't exist inside the character..
as for the near to the player spawning you need the Vector3:Normal between the part your firing from and the mouse.hit.position Basically its the direction your pointing...
In code this would be:
local LookDir = (Mouse.hit.Position - FirePoint.Position).unit
local Speed = 50
local Velocity = LookDir * Speed
local Spawned_part = Vector3.new(0,0,3)
local FirePoint = Vector3.new(0,0,0)
local MouseHit = Vector3.new(0,20,0)
Spawn part will get to the position Spawned Point + MouseHit and that would be
local SpawnedPart_Goal = Vector3.new(0,20,3)
hope this helps!
2 comments
I think it's the aaa.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
what exactly is wrong with it @failypal