I have an ability script I made and there is a bug I need help fixing. Whenever someone does the ability if they die during the ability the wall doesn’t destroy itself, How could I fix this?
local SS = game:GetService("ServerScriptService")
local RS = game:GetService("ReplicatedStorage")
local HammersModule = require(RS.HammersModule)
local TweenService = game:GetService("TweenService")
local Tool = script.Parent.Parent.Parent
local Utility = Tool:FindFirstChild("Utility")
Utility.Ability.OnServerEvent:Connect(function(Player)
local Char = Player.Character
local HRP = Char:WaitForChild("HumanoidRootPart")
local Wall = RS.Abilities.BrickHammer.BrickWall:Clone()
Wall.CFrame = HRP.CFrame * CFrame.new(0, -10, -10)
Wall.Parent = workspace
local Sound = Instance.new("Sound")
Sound.SoundId = HammersModule["Normal Hammers"][Tool.Name]["Ability SoundID"]
Sound.Volume = HammersModule["Normal Hammers"][Tool.Name]["Ability Volume"]
Sound.TimePosition = 0.87
Sound.RollOffMaxDistance = 50
Sound.RollOffMinDistance = 4
Sound.Parent = Wall
local goal1 = {}
goal1.CFrame = HRP.CFrame * CFrame.new(0, 0, -10)
local tweenInfo1 = TweenInfo.new(1.3,Enum.EasingStyle.Bounce)
local tween1 = TweenService:Create(Wall, tweenInfo1, goal1)
local goal2 = {}
goal2.CFrame = HRP.CFrame * CFrame.new(0, -10, -10)
local tweenInfo2 = TweenInfo.new(1.3,Enum.EasingStyle.Quint)
local tween2 = TweenService:Create(Wall, tweenInfo2, goal2)
Wall.ParticleEmitter.Enabled = true
tween1:Play()
Sound:Play()
wait(0.3)
Wall.ParticleEmitter.Enabled = false
wait(5)
Wall.ParticleEmitter.Enabled = true
tween2:Play()
Sound:Play()
wait(0.3)
Wall.ParticleEmitter.Enabled = false
wait(1)
Wall:Destroy()
Sound:Destroy()
end)
Then do a check to see when the player has died
An example:
local Players = game:GetService("Players")
local function onPlayerAdded(player)
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
local function onDied()
print(player.Name, "has died!")
end
humanoid.Died:Connect(onDied)
end
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)
Where would I put this in the script because if the player dies I need to be able to check for the wall clone to delete it?
Something like this, I would have to go into studio to actually do testing
local replicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local module = require(replicatedStorage.HammersModule)
local tool = script.Parent.Parent.Parent
local event = tool:FindFirstChild("Utility")
event.Ability.OnServerEvent:Connect(function(player)
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
local clone = replicatedStorage.Abilities.BrickHammer.BrickWall:Clone()
clone.CFrame = humanoidRootPart.CFrame * CFrame.new(0, -10, -10)
clone.Parent = workspace
local sound = Instance.new("Sound")
sound.SoundId = module["Normal Hammers"][tool.Name]["Ability SoundID"]
sound.Volume = module["Normal Hammers"][tool.Name]["Ability Volume"]
sound.TimePosition = 0.87
sound.RollOffMaxDistance = 50
sound.RollOffMinDistance = 4
sound.Parent = clone
local tween1 = TweenService:Create(
clone,
TweenInfo.new(1.3, Enum.EasingStyle.Bounce),
{CFrame = humanoidRootPart.CFrame * CFrame.new(0, 0, -10)})
local tween2 = TweenService:Create(
clone,
TweenInfo.new(1.3, Enum.EasingStyle.Quint),
{CFrame = humanoidRootPart.CFrame * CFrame.new(0, -10, -10)})
clone.ParticleEmitter.Enabled = true
tween1:Play()
sound:Play()
wait(0.3)
clone.ParticleEmitter.Enabled = false
wait(5)
clone.ParticleEmitter.Enabled = true
tween2:Play()
sound:Play()
wait(0.3)
clone.ParticleEmitter.Enabled = false
wait(1)
clone:Destroy()
sound:Destroy()
humanoid.Died:Connect(function()
clone:Destroy()
end)
end)