Position offset

Hello!

I’m currently working a fireball script. When hitting a target an explosion will happen and a hitbox will be created, damaging the enemy. Everything is working just fine until the fireball is hitting a target. When it does, the hitbox created will have the same position as the fireball, but for some reason it’s going to have a different offset, as you can see in this gif: https://gyazo.com/7cd50e62fe24080bd1399369a9b525b3 .

I tried searching for solutions on both devforum and scriptinghelpers but couldn’t find anything. Welding the hitbox to the fireball won’t work either.

1 Like

Is the hitbox a part or a model?

Edit: I misspelled 2 words, sorry.

The hitbox itself is a part, not a model.

1 Like

Ok. How did you set the position of the hitbox? CFrame or Position?

An even better question: You are probably firing a remote event/function to create the hitbox on the server… Are you sending the fireball’s position right when it touches something or did you store the position in a variable before the fireball touches anything?

It would be better if you pasted the code here.

part.Touched:Connect(function(hitPart)
                if triggered then return end
                if functions.CheckForSolidPart(hitPart, Character) == true then
                    triggered = true
                    part.Anchored = true
                    local pos = part.Position
                    local explosion = part
                    --local explosion = game.ServerStorage.Assets["Fire Magic"]["Fireball Explosion"]:Clone()
                    --explosion.Parent = workspace.Effects
                    --explosion:SetPrimaryPartCFrame(part.CFrame)
                    --print(explosion.PrimaryPart.Position)
                    -------------------------------------------------------
                    local hitbox = Instance.new("Part", workspace.Effects)
                    hitbox.Size = Vector3.new(15,15,15)
                    hitbox.CanCollide = false
                    hitbox.Transparency = 0
                    hitbox.Anchored = true
                    hitbox.Massless = true
                    local weld = Instance.new("Weld", hitbox)
                    weld.Part0 = weld.Parent
                    weld.Part1 = part
                    game.Debris:AddItem(hitbox, 0.1)
                    hitbox.Position = part.Position
                    print(hitbox.Position)
                    --------------------------------------------------------
                    functions.Damage(Player.Character, hitbox, 10, 1, true)
                    tweenService:Create(explosion, TweenInfo.new(1), {Size = Vector3.new(35,35,35), Transparency = 1}):Play()
                    game.Debris:AddItem(explosion, 1)
                    wait(0.4)
                    print(part.Position)
                    --part:Destroy()
                    if functions.GetPointUnder(part, 15) then
                        --print("Yes")
                    end
                end
            end)
1 Like

This code is inside a Server Script or a LocalScript?

The code is inside a server script.

1 Like

Instead of doing

hitbox.Position = part.Position

do

hitbox.Position = hitPart.Position

If that doesn’t work then I’ll try using CFrame instead of position, because position sometimes doesn’t function properly for me.

Any part that isn’t in a folder called “Effects” will be considered a solid part by the script. If I hit a bigger part then it will go straight to the middle of the part hit. I’ll try CFrame.

1 Like

Wait, my brain is confusion! Are the parts inside of the folder Effects kind of whitelisted?

Why are there commented out areas inside the script you showed?

In the code I sent above, you can see a function called CheckForSolidPart. This is how it works:

function module.CheckForSolidPart(Part, PCharacter)
	if Part == nil then return end
	if Part.Parent == nil then return end
	if Part.Parent == workspace.Effects or Part.Parent.Parent == workspace.Effects or Part.Parent.Parent.Parent == workspace.Effects or Part.Parent == PCharacter or Part.Parent.Parent == PCharacter then
		return false
	else
		return true
	end
end
1 Like

Because at first I was using a model to replicate the explosion that was meant to happen, and then made the actual projectile bigger after I noticed that it happens the same with the cloned explosion model.

1 Like

You can simply do

function module.CheckForSolidPart(Part, PCharacter)
	if Part == nil then return end
	if Part.Parent == nil then return end
	if Part:IsDescendantOf(workspace.Effects) or Part:IsDescendantOf(PCharacter) then
		return false
	else
		return true
	end
end

I didn’t know about that honestly. The code sure does look cleaner now and I’m very thankful for that, but the offset problem still occurs.

1 Like

Ok. I’ll head back into the problem.

Also tried using Rotated Region3 Module by EgoMoose to make a Region3 hitbox but it happens the exact same. I think it’s because of roblox’s physics engine?

1 Like