-
What do you want to achieve? Keep it simple and clear!
I want the bullet to go where i click my mouse -
What is the issue? Include screenshots / videos if possible!
for some reason it goes in the wrong direction -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i tried making the raycast starts from the player character but that made it worse
here is a video showing the issue
robloxapp-20240519-0845477.wmv (75.3 KB)
a localscript when a player activates the gun
local ForceVector
script.Parent.Activated:Connect(function()
local UIS = game:GetService("UserInputService")
local MouseLocation = UIS:GetMouseLocation()
local Cam = game.Workspace.CurrentCamera
local MouseVector = Cam:ViewportPointToRay(MouseLocation.X,MouseLocation.Y)
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {game.Players.LocalPlayer.Character}
Params.FilterType = Enum.RaycastFilterType.Exclude
local RootPartCF
local Result = workspace:Raycast(MouseVector.Origin,MouseVector.Direction * 10000,Params)
if Result.Position.X > game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame.X then
local RootPart = game.Players.LocalPlayer.Character.HumanoidRootPart
RootPartCF = CFrame.lookAt(RootPart.Position,Vector3.new(RootPart.Position.X + 50,RootPart.Position.Y,RootPart.Position.Z))
else
local RootPart = game.Players.LocalPlayer.Character.HumanoidRootPart
RootPartCF = CFrame.lookAt(RootPart.Position,Vector3.new(RootPart.Position.X + -50,RootPart.Position.Y,RootPart.Position.Z))
end
ForceVector = Vector3.new(Result.Position.X,Result.Position.Y,2)
script.Parent.RemoteEvent:FireServer(RootPartCF)
end)
script.Parent.RemoteEvent.OnClientEvent:Connect(function()
local Bullet = Instance.new("Part",workspace)
local Attachment = Instance.new("Attachment",Bullet)
local VectorForce = Instance.new("VectorForce",Bullet)
Bullet.Size = Vector3.new(0.25, 1, 0.25)
local BulletStart = script.Parent.BulletStart.Position
Bullet.Position = Vector3.new(BulletStart.X,BulletStart.Y,2)
Bullet.Color = Color3.fromRGB(255, 255, 0)
Bullet.Material =Enum.Material.Neon
VectorForce.Attachment0 = Attachment
VectorForce.Enabled = true
VectorForce.ApplyAtCenterOfMass = true
VectorForce.RelativeTo = Enum.ActuatorRelativeTo.World
VectorForce.Force = ForceVector
local Db = {}
Bullet.Touched:Connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") and not Db[hit.Parent] then
Db[hit.Parent] = true
hit.Parent.Humanoid:TakeDamage(10)
Bullet:Destroy()
task.wait(0.2)
Db[hit.Parent] = false
else
Bullet:Destroy()
end
end)
end)
The script when the remote event is fired
script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr,ForceVector,RootPartCF)
script.Parent.RemoteEvent:FireAllClients(ForceVector)
plr.Character.HumanoidRootPart.CFrame = RootPartCF
end)