Help with devil fruit script

so, I’m making a game like one piece, I made an invisibility fruit and there is a “shot” ability, when a projectile hits a wall, a small explosion appears, but sometimes the projectile disappears too quickly and the explosion appears either after the wall or in the air in front of the wall, and so , how can I make the explosion more correct, maybe I don’t need to use the on-touch function?

here’s the script

function tagHumanoid(Enemy, player)
local creator_tag = Instance.new(“ObjectValue”)
creator_tag.Value = player
creator_tag.Name = “creator”
creator_tag.Parent = Enemy
end
function untagHumanoid(Enemy)
if Enemy ~= nil then
local tag = Enemy:findFirstChild(“creator”)
if tag ~= nil then
tag.Parent = nil
end
end
end
script.Parent.OnServerEvent:Connect(function(plr,direction,mouseaim)
local OnHit = false
local Alive = true
local EZ = plr.Character:WaitForChild(“HumanoidRootPart”)
local Projectile = game.Workspace.AttackEffects[plr.Name…"'s Invisible Rock"]
plr.Character.RightHand.InvisibleRock:Destroy() --OnHand Skill Destroy
wait(.01)
Projectile.CanCollide = false
Projectile.Orientation = Projectile.Orientation + Vector3.new(0,0,0)
local Damage = 5
Projectile.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) and hit.Parent.Name ~= plr.Name then
if not hit.Parent.Humanoid:FindFirstChild(plr.Name) then
local ws = hit.Parent.Humanoid.WalkSpeed
local An = hit.Parent.Humanoid:LoadAnimation(game.ReplicatedStorage.Powers.InvisiblityMR.HitAnim)
An:Play()
hit.Parent.Humanoid.WalkSpeed = hit.Parent.Humanoid.WalkSpeed - 10
game.ReplicatedStorage.ShakeEvents.NormalExplosion:FireAllClients()
hit.Parent.Humanoid:TakeDamage(Damage)
Projectile:Destroy()
local Explosion = game.ReplicatedStorage.Powers.InvisiblityMR.Smoke:Clone()
Explosion.Parent = workspace.AttackEffects
Explosion.CFrame = hit.Parent.HumanoidRootPart.CFrame * CFrame.new(0,0,0)
Explosion.Anchored = true
Explosion.CanCollide = false
Explosion.CFrame = Projectile.CFrame * CFrame.new(0,0,0)
if hit.Parent.Data.Diamond.Value == true or game.Players:FindFirstChild(hit.Parent.Name) and game.Players[hit.Parent.Name].PLRSettings.DiamondTransform.Value == true then
Explosion.Attachment.TracesColored.Color = ColorSequence.new(hit.Color)
Explosion.Attachment.TracesColored:Emit(10) --set 5
Explosion.Attachment.HitFX:Emit(1)
Explosion.Attachment.Swirl:Emit(5)
Explosion.Attachment.Diamond:Emit(35)
wait(0.2)
hit.Parent.Humanoid.WalkSpeed = ws
An:Destroy()
wait(2)
Explosion:Destroy()
end
if hit.Parent.Data.Diamond.Value == false or game.Players:FindFirstChild(hit.Parent.Name) and game.Players[hit.Parent.Name].PLRSettings.DiamondTransform.Value == false then
Explosion.Attachment.TracesColored.Color = ColorSequence.new(hit.Color)
Explosion.Attachment.TracesColored:Emit(10) --set 5
Explosion.Attachment.HitFX:Emit(1)
Explosion.Attachment.Swirl:Emit(5)
Explosion.Attachment.Blood:Emit(35)
wait(0.2)
hit.Parent.Humanoid.WalkSpeed = ws
An:Destroy()
wait(2)
Explosion:Destroy()
end
end
end
if hit:IsA(“Part”) or hit.Parent:FindFirstChild(“MeshPart”) or hit.Parent:FindFirstChild(“UnionOperation”) and hit.Parent.Name ~= plr.Name then
local Explosion2 = game.ReplicatedStorage.Powers.InvisiblityMR.Smoke:Clone()
Explosion2.Parent = workspace.AttackEffects
Explosion2.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) and hit.Parent.Name ~= plr.Name then
if not hit.Parent.Humanoid:FindFirstChild(plr.Name) then
local ws = hit.Parent.Humanoid.WalkSpeed
local An = hit.Parent.Humanoid:LoadAnimation(game.ReplicatedStorage.Powers.InvisiblityMR.HitAnim)
An:Play()
hit.Parent.Humanoid.WalkSpeed = hit.Parent.Humanoid.WalkSpeed - 10
local Damage = (10)
hit.Parent.Humanoid:TakeDamage(Damage)
wait(0.2)
hit.Parent.Humanoid.WalkSpeed = ws
An:Destroy()
end
end
end)
local An = Instance.new(“Animation”)
An.Parent = Explosion2
An.Name = plr.Name
game.ReplicatedStorage.ShakeEvents.Explosion:FireAllClients()
Explosion2.Anchored = true
Explosion2.CanCollide = false
Explosion2.CFrame = Projectile.CFrame * CFrame.new(0,0,0)
if hit.Parent.Name ~= “BarrierWall” or hit.Name ~= “BarrierWall” then
Explosion2.Attachment.TracesColored.Color = ColorSequence.new(hit.Color)
Explosion2.Attachment.TracesColored:Emit(10) --set 5
Explosion2.Attachment.HitFX:Emit(1)
Explosion2.Attachment.Swirl:Emit(5)
Projectile:Destroy()
wait(3)
Explosion2:Destroy()
end
end
end)
local BV = Instance.new(“BodyVelocity”,Projectile)
BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BV.Velocity = CFrame.new(plr.Character.RightHand.Position,mouseaim).LookVector * 150 --Make part flying
wait(1)
BV:Destroy() – Bullet Destroy if not touched part/humanoid
wait(2)
Projectile:Destroy()
end)

1 Like