Hi,
I want to make a magic fireball, which explodes when it touches something, works with a bodyVelocity whose velocity goes towards the mouse position. and use the Touched event to explode.
the problem is that when the fireball hits a part there is a little delay and then it explodes.
I have tried with changing the part collisions, using moduleScripts but it doesn’t work.
moduleScript code:
local function detonar(plr,clon,hit)
local h = hit.Parent:FindFirstChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if hit.Parent ~= plr.Character and h then
clon.PrimaryPart.Anchored = true
h.Health = h.Health - 5
end
if clon.enabled.Value == true then
clon.PrimaryPart.Trail.Enabled = false
clon.enabled.Value = false
clon.PrimaryPart.CanCollide = false
clon.PrimaryPart.efectoSonido:Play()
clon.PrimaryPart.Anchored = true
for i = 0,1,.02 do
for k, v in pairs(clon:GetChildren()) do
if v:IsA("BasePart") then
local hondaValue = v:FindFirstChild("honda")
if not hondaValue then
v.Transparency = i
v.Size = v.Size + Vector3.new(1,1,1)
elseif hondaValue and hondaValue.Value == true then
if v.Transparency == 1 then
v.Transparency = 0.5
end
v.Size = v.Size + Vector3.new(5,0.1,5)
v.Transparency = v.Transparency + .02
end
end
end
wait()
end
for k, v in pairs(clon:GetChildren()) do
if v:IsA("BasePart") then
v.Transparency = 1
end
end
wait(0.2)
clon:Destroy()
end
end
return detonar
ServerScript code:
local event = game.ReplicatedStorage.remotes.disparar
local animation = game.ReplicatedStorage.Animatios.Poder1
local capeta = game.ReplicatedStorage.PowerMeshes.Poder1:GetChildren()
local detonar = require(game.ReplicatedStorage.Modules.DetonarBolaDeFuego)
event.OnServerEvent:Connect(function(plr,pos)
if plr.Character.Humanoid.Health <= 0 then
return
end
local character = plr.Character
character.Humanoid:LoadAnimation(animation):Play()
local clon = capeta[math.random(1,#capeta)]:Clone()
local weld = Instance.new("WeldConstraint",clon)
clon.Parent = workspace
clon:SetPrimaryPartCFrame(character.RightHand.CFrame)
weld.Part0 = character.RightHand
weld.Part1 = clon.PrimaryPart
wait(0.95)
clon.PrimaryPart.Trail.Enabled = true
weld:Destroy()
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Parent = clon.PrimaryPart
bodyVelocity.Velocity = CFrame.new(clon.PrimaryPart.Position,pos).LookVector*100
clon.PrimaryPart.Touched:Connect(function(hit)
if hit.Parent ~= plr.Character then
clon.PrimaryPart.Anchored = true
bodyVelocity:Destroy()
detonar(plr,clon,hit)
end
end)
end)
Thank you for reading.