So my projectile is fine most of the time, it hits where it should be but sometimes when it reaches the hit point it can glitch and do some weird things that will be shown in the following gif:
https://gyazo.com/380995fe03a987e9a5147af70af2dd3e
ignore that part there its not the cause, I just added a part on the hit position to see if the problem is with the tweening of when the ray detects the hit part
The code:
function NormalSpellCast(SpellName, Wand, Player, MouseHitP)
local ColorValue = ReplicatedStorage.Spells:FindFirstChild(SpellName).ColorValue.Value
if Wand.Rapid.Value == false then
Wand.Spell.Value = ""
end
local TheBullet = ReplicatedStorage.BULLET:Clone()
TheBullet.Trail.Color = ColorSequence.new(ColorValue)
TheBullet.PointLight.Color = ColorValue
TheBullet.Parent = workspace.Spells
TheBullet.CFrame = Wand.Handle.Tip.CFrame
local Ignore = {Player.Character, workspace.Spells, workspace.Effects}
local Region3Module = require(script.RotatedRegion3)
local InputRegion = Region3Module.fromPart(Wand.Handle.Tip) -- creates a region based on your part's size and location
local InsideInput = InputRegion:cast({Player.Character, workspace.Spells, workspace.Effects, workspace.Characters, workspace.NPCs}, 1000)
if #InsideInput == 0 then
repeat
local SpellRay = Ray.new(TheBullet.CFrame.p, (MouseHitP - TheBullet.CFrame.p).Unit * 15)
local Hit, Position = workspace:FindPartOnRayWithIgnoreList(SpellRay, Ignore)
local TweenInformation = TweenInfo.new(0.05, Enum.EasingStyle.Linear)
local TweenGoals = {
CFrame = CFrame.new(Position) --* CFrame.new(math.random(-1,1), math.random(-1,1), math.random(-1,1))
}
local TweenAnimation = TweenService:Create(TheBullet, TweenInformation, TweenGoals)
TweenAnimation:Play()
if Hit then
local TweenInformation = TweenInfo.new(0.05, Enum.EasingStyle.Linear)
local TweenGoals = {
CFrame = CFrame.new(Position)
}
local TweenAnimation = TweenService:Create(TheBullet, TweenInformation, TweenGoals)
TweenAnimation:Play()
TweenAnimation.Completed:Wait()
local h = Hit.Parent:FindFirstChildOfClass("Humanoid") or Hit.Parent.Parent:FindFirstChildOfClass("Humanoid")
if h ~= nil then
if h.Parent:FindFirstChild("Ignore") then
else
if h.Health > 0 then
TheBullet:Destroy()
SpellHit(SpellName, h.Parent, Player)
end
end
else
TheBullet:Destroy()
local Effect = ReplicatedStorage.EFFECT:Clone()
Effect.Attachment.Sparks.Color = ColorSequence.new(ColorValue)
Effect.Attachment.Sparks2.Color = ColorSequence.new(ColorValue)
Effect.Parent = workspace.Effects
Effect.Position = Position
Effect.Script.Disabled = false
game.Debris:AddItem(Effect,1)
end
end
until Hit or ((TheBullet.CFrame.p - Wand.Handle.Tip.CFrame.p).Magnitude > 2000)
game:GetService("Debris"):AddItem(TheBullet, 0.5)
else
TheBullet:Destroy()
end
end
