the thing i am trying to achieve - i use remote event to deal damage to enemies and to destroy boxes
it has been working until i added the box, when the player destroys the box then dies, the slide(how i deal damage) no longer works,
ive tried messing around with it but to no avail so far here is the issue in video form
robloxapp-20240206-1841398.wmv (2.7 MB)
i also get this error once i die
it seems to me everything is connected as sometimes killing one npc will kill others and destroying the box can have the same result
here is the script, first function for the npc killing the second for the box destroying
function SlideDmg(hit)
local Bob = game.Workspace["Level 1"].Enemies.Bob
Character = hit.Parent
if hit.Parent and SlideTrack.IsPlaying then
game.ReplicatedStorage.DamageEvent:FireServer(Bob)
task.wait()
end
end
function destroyBox(hit)
Character = hit.Parent
if hit.Parent:FindFirstChildOfClass("Humanoid") and SlideTrack.IsPlaying then
game.ReplicatedStorage.BoxEvent:FireServer(box)
end
end
the other part of the remote events
local coinBindable = game.ReplicatedStorage.CoinBindable
game.ReplicatedStorage.DamageEvent.OnServerEvent:Connect(function(Player, Bob)
Bob:WaitForChild("HumanoidRootPart").ParticleEmitter.Enabled = true
task.wait(0.5)
Bob.Parent = game.ServerStorage
wait(10)
Bob:WaitForChild("HumanoidRootPart").ParticleEmitter.Enabled = false
Bob.Parent = game.Workspace["Level 1"].Enemies.Bob
end)
game.ReplicatedStorage.BoxEvent.OnServerEvent:Connect(function(Player, box)
task.wait(0.5)
box:Destroy()
coinBindable:Fire()
end)
the line that errors is the touched event for the box this is obviously because it no longer exists but the error only fires once the player dies
edit i dont know if this part is relevant but since it involves the slide function also here is that just in case
local function Slide(input, _gameProcessed)
if _gameProcessed then return end
if input.KeyCode == Enum.KeyCode.LeftShift and Humanoid.MoveDirection.Magnitude > 0 then
if debounce then
return
end
debounce = true
Humanoid.JumpPower = 0
WalkTrack:Stop()
task.wait(0.1)
SlideTrack:Play()
if SlideTrack.IsPlaying then
LFEmitter.Enabled = true
RFEmitter.Enabled = true
end
task.wait(1)
SlideTrack:Stop()
Humanoid.JumpPower = 50
debounce = false
if SlideTrack.IsPlaying == false then
LFEmitter.Enabled = false
RFEmitter.Enabled = false
end
end
end