Alright so I have this gun that I created using Raycasting but the projectile that comes off the gun doesn’t have the same size as the ray that I casted from the gun, it might not be the projectile’s fault but I think that it is, anyways here’s a GIF which shows my issue:
As you can see in the GIF, the gun projectile’s size isn’t what it is intended to be instead it looks weird since it’s supposed to shoot forward 30 studs in the Z axis but it doesn’t and the hinge is for the gun’s front surface I made it like that so it is easier for me to see where the gun’s front surface is.
Here’s the script that I’m using which also includes comments to help you understand what I’m doing that also explains what important lines of the code does which can possibly be the issue:
Code
local tool = script.Parent
local Debris = game:GetService("Debris")
local toolHandle = tool.Handle -- Getting the tool's Handle which is the only part that I'm using to create this gun.
local rayOrigin = toolHandle.CFrame.LookVector -- This is where the ray starts.
local rayDirection = toolHandle.CFrame.LookVector + Vector3.new(0,0,30) -- This is where the ray will go.
local gunRay = Ray.new(rayOrigin,rayDirection) -- Creating the ray.
tool.Activated:Connect(function()
local thing, hit = workspace:FindPartOnRayWithIgnoreList(gunRay,{toolHandle}) -- Casting the ray.
local part = Instance.new("Part") -- This is where I create the part and modify the properties of the part.
part.Transparency = 0
part.Anchored = true
part.CanCollide = false
part.Color = Color3.fromRGB(255,0,0)
part.CFrame = toolHandle.CFrame
part.Size = Vector3.new(0,0,30) -- Maybe this is the issue?
part.Parent = workspace
Debris:AddItem(part,0.2)
end)