Here's a proper question.
I've been working on this for days now and this part has always been hard to figure out. Its suppose to shoot where the mouse is pointing but instead it shoots near or doesn't shoot near the mouse at all. below is the code
local yes = game.Players.LocalPlayer:GetMouse() local baconflake = script.baconflake:Clone() local aaa = Instance.new("BodyVelocity") baconflake.Anchored = false baconflake.CFrame = ch["Torso"].CFrame baconflake.Parent = workspace aaa.MaxForce = Vector3.new(math.huge,math.huge,math.huge) aaa.Velocity = yes.hit.p aaa.Parent = baconflake
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() -- dont actually need this function this is just my way to get the base where you fire a ball from as in Character.Torso if that doesn't exist then it will warn you that it doesn't exist and return the humanoidrootpart as default!. 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() --// just overridden with a part since i dont have what you have inside your script! 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 --// to fire somthing at 50 studs away from you towards your mouse pointer simply do this local Velocity = LookDir * Speed --// now just apply that Velocity to a part and BAM you've got a part moving away from you, assuming you spawned it at your FirePoint. If its not then it will try to get to the `mouse.hit.p` but it will be offset by where you spawned your part. 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) -- or close to!
hope this helps!