Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does this projectile create the explosion to early?

I made this script in the projectile sent from a tool I made but when it hits something, it creates the explosion too early, and not where the explosion is supposed to happen

script.Parent.Touched:Connect(function(Hit)
	if Hit.Parent == script.Parent.Caster.Value or Hit.Parent.Parent == script.Parent.Caster.Value then
		return
	end
	local Blast = game:GetService("ServerStorage").Explosiont:Clone()
	Blast.Parent = workspace.Spells
	local Humanoid = Hit.Parent:FindFirstChildWhichIsA("Humanoid") or false
	if Humanoid then
		Humanoid:TakeDamage(20)
	end
	Blast.Position = script.Parent.Position
	Blast.EnergyBallBlast.Position = Blast.Position
	script.Parent:Destroy()
end)

I have figured it is not accurately getting the position of the ball when it is supposed to explode. It should explode as soon as it hits and the explosion should be right at the point of impact. Please help

2 comments

0

i see nothing wrong with ur script; perhaps when u fire the thing body parts of ur character are blocking the projectile?

0

no

1 answer

I believe your projectile is hitting your character. Your script is detecting if the string value of "Caster" is the part that hit it. Basically, you are trying to check if the part that hit your projectile is a username, and obviously the hit part is not a name, it is a part. So, you should be checking if the name of the hit part is equal to your string value. I went ahead and fixed that, so it should not be hitting your character anymore. Try this:

script.Parent.Touched:Connect(function(Hit)
    if Hit.Parent.Name == script.Parent.Caster.Value or Hit.Parent.Parent.Name == script.Parent.Caster.Value then
        return
    end
    local Blast = game:GetService("ServerStorage").Explosiont:Clone()
    Blast.Parent = workspace.Spells
    local Humanoid = Hit.Parent:FindFirstChildWhichIsA("Humanoid") or false
    if Humanoid then
        Humanoid:TakeDamage(20)
    end
    Blast.Position = script.Parent.Position
    Blast.EnergyBallBlast.Position = Blast.Position
    script.Parent:Destroy()
end)

Also, on line 6 your explosion is named "Explosiont" I'm not sure if this is a typo or on purpose, but I would fix that if it's a typo. I left it as is in the case that you did that on purpose.

This discussion is preserved as it was. New answers, comments, and votes are closed.