Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script broke after used twice, why?

Asked by 3 years ago

I was creating a fireball and it's actually working fine but after it's used twice it broke like this.

local remotes = script.Parent.Remotes
local assets = game.ReplicatedStorage.FireAssets
local keyholded = false

local Tweenservice = game:GetService("TweenService")
local info = TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0)

local explosioninfo = TweenInfo.new(3.5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0)
local damagebonus = 0

local db = false

remotes.KeyHolded.OnServerEvent:Connect(function(plr, skill)
    if skill == "Fireball" then
        if not keyholded then       
            keyholded = true    

        local char = plr.Character
        local humrp = char.HumanoidRootPart
        local magiccircle = assets.MagicCircle.Q

        local base = assets.MagicCircle.Q.Center:Clone()
        base.CFrame = humrp.CFrame
            base.Parent = humrp

        local base2 = assets.MagicCircle.Q.Center2:Clone()
        base.CFrame = humrp.CFrame
            base2.Parent = humrp

        local base3 = assets.MagicCircle.Q.Center3:Clone()
        base.CFrame = humrp.CFrame
            base3.Parent = humrp

        local weld = Instance.new("ManualWeld")
        weld.Part0 = base
        weld.Part1 = humrp
        weld.C1 = CFrame.new(1,1,-2)
        weld.Parent = base

        local weld2 = Instance.new("ManualWeld")
        weld2.Part0 = base2
        weld2.Part1 = humrp
        weld2.C1 = CFrame.new(1,1,-3)
        weld2.Parent = base2

        local weld3 = Instance.new("ManualWeld")
        weld3.Part0 = base3
        weld3.Part1 = humrp
        weld3.C1 = CFrame.new(1,1,-4)
        weld3.Parent = base3

        local castsound = script.Parent.Sounds.cast:Clone()
        castsound.Parent = plr.Character.HumanoidRootPart
        castsound:Play()

        Tweenservice:Create(base,info,{Size = Vector3.new(8.223, 8.54, 0.05)}):Play()   
        Tweenservice:Create(base2,info,{Size = Vector3.new(6.008, 6.145, 0.05)}):Play() 
            Tweenservice:Create(base3,info,{Size = Vector3.new(3.613, 3.791, 0.05)}):Play()

            while keyholded == true do
                wait(1)
                damagebonus = damagebonus + 25
            end

        wait(1.5)
        castsound:Destroy()
        end
    else
        keyholded = false
        Tweenservice:Create(plr.Character.HumanoidRootPart.Center,TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Size = Vector3.new(0,0,0)}):Play()
        Tweenservice:Create(plr.Character.HumanoidRootPart.Center2,TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Size = Vector3.new(0,0,0)}):Play()
        Tweenservice:Create(plr.Character.HumanoidRootPart.Center3,TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Size = Vector3.new(0,0,0)}):Play()
        Tweenservice:Create(plr.Character.HumanoidRootPart.Center.PointLight,TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Brightness = 0}):Play()
        Tweenservice:Create(plr.Character.HumanoidRootPart.Center2.PointLight,TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Brightness = 0}):Play()
        Tweenservice:Create(plr.Character.HumanoidRootPart.Center3.PointLight,TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Brightness = 0}):Play()
    end
end)

remotes.FireRemote.OnServerEvent:Connect(function(plr, skill)
    if skill == "Fireball" then
        local char = plr.Character
        local newblast = assets.QMove.FireQ:Clone()
        newblast.CFrame = plr.Character.HumanoidRootPart.Center3.CFrame * CFrame.new(0,0,-4)

        local bv = Instance.new("BodyVelocity", newblast)
        bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
        bv.Velocity = (char.HumanoidRootPart.CFrame.lookVector * 80)

        newblast.Parent = plr.Character.HumanoidRootPart

        local name = Instance.new("StringValue",newblast)
        name.Name = "Owner"
        name.Value = plr.Name

        local shootsound = script.Parent.Sounds.shoot:Clone()
        shootsound.Parent = plr.Character.HumanoidRootPart
        shootsound:Play()

        newblast.Touched:Connect(function(hit)
            if hit ~= nil then
                if hit.Name ~= "wave" and hit.Name ~= "explosion" and hit.Name ~= "Center" and hit.Name ~= "Center2" and hit.Name ~= "Center3" and hit.Name ~= "epic" then
                    if not db then
                        db = true

                        newblast.Anchored = true
                        newblast.ba.Enabled = false
                        newblast.w.Enabled = false

                        local e1 = assets.QMove.ontouch.explosion:Clone()
                        e1.Parent = workspace
                        e1.CFrame = newblast.CFrame
                        local e2 = assets.QMove.ontouch.wave:Clone()
                        e2.Parent = workspace
                        e2.CFrame = newblast.CFrame
                        local e3 = assets.QMove.ontouch.epic:Clone()
                        e3.Parent = workspace
                        e3.CFrame = newblast.CFrame

                        local explosionsound = script.Parent.Sounds.hit:Clone()
                        explosionsound.Parent = e1
                        explosionsound:Play()

                        Tweenservice:Create(e1,explosioninfo,{Size = Vector3.new(77.983, 77.983, 77.983),Transparency = 1}):Play()
                        Tweenservice:Create(e2,explosioninfo,{Size = Vector3.new(144.179, 7.357, 141.394), Transparency = 1}):Play()
                        Tweenservice:Create(e3,explosioninfo,{Size = Vector3.new(112.292, 82.969, 105.335), Transparency = 1}):Play()

                        for i, v in pairs(workspace:GetChildren()) do
                            if v ~= workspace:FindFirstChild(newblast:FindFirstChild("Owner").Value) then
                                if v:FindFirstChild("HumanoidRootPart") and v:FindFirstChildOfClass("Humanoid") then
                                    local hum = v:FindFirstChildOfClass("Humanoid")
                                    local humrp = v:FindFirstChild("HumanoidRootPart")
                                    if hum.Health > 0 then
                                        if (newblast.Position - humrp.Position).magnitude < 20 then
                                            hum:TakeDamage(800 + damagebonus)
                                            damagebonus = 0
                                        end
                                    end
                                end
                            end
                        end

                        e1.explode1.Enabled = true
                        e1.explode2.Enabled = true
                        e1.explode3.Enabled = true
                        e1.explode4.Enabled = true
                        wait(0.5)
                        e1.explode1.Enabled = false
                        e1.explode2.Enabled = false
                        e1.explode3.Enabled = false
                        e1.explode4.Enabled = false

                        wait(1)
                        local smoke = assets.QMove.ontouch.Smoke:Clone()
                        smoke.Parent = workspace
                        smoke.CFrame = e1.CFrame
                        newblast.ba.Enabled = false
                        newblast.w.Enabled = false
                        db = false

                        local smokesound = script.Parent.Sounds.smoke:Clone()
                        smokesound.Parent = smoke
                        smokesound:Play()

                        Tweenservice:Create(smoke,TweenInfo.new(2.5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Size = Vector3.new(91.99, 77.722, 94.663)}):Play()
                        wait(0.5)
                        Tweenservice:Create(smoke,TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Transparency = 1}):Play()
                        wait(2)
                        plr.Character.HumanoidRootPart:FindFirstChild("Center"):Destroy()
                        plr.Character.HumanoidRootPart:FindFirstChild("Center2"):Destroy()
                        plr.Character.HumanoidRootPart:FindFirstChild("Center3"):Destroy()
                        wait(1)
                        e1:Destroy()
                        e2:Destroy()
                        e3:Destroy()
                        smoke:Destroy()
                        newblast:Destroy()
                    end
                end
            end
        end)
    end
end)
0
are there errors? debugging 182 lines without much help is not exactly what you should be asking for, you should give more context to your question. Errors if any, line which handles the problematic part... imKirda 4491 — 3y
0
bet you 20 bucks its because he didn't clone somewhere Feroxidus 83 — 3y
0
well actually i dont see any errors in output, i guess the script are deleting the first magic circle that is cloned. cause the magic circle only deleted when the first fireball collide with something Salvin_Gaming 10 — 3y
0
Ok nvm i found the fix , i just need to make it destroy instantly after the tweening is completed. Lmao my bad, that was a easy fix xd Salvin_Gaming 10 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

Ok, i found the fix by myself, i make the script destroy the magic circle right after the tweening is completed. Yeah lmao that was an easy fix.

0
nope your issue is you didnt clone it before destroying. your current version will break with multiple people. Feroxidus 83 — 3y
0
i did? line 22 - 32 Salvin_Gaming 10 — 3y
Ad

Answer this question