So im making a game similar to ability wars or slap battles, and currently am making an ability called “peel”
peel will be able to place multiple banana peels, and when someone steps on them, they get destroyed and ragdoll the player. im having an issue with destroying the peel. when you place multiple, all of them are destroyed even when only one is stepped on. how do I fix this?
script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr)
if cooldowns.is_cd(plr, attack_name) or db == true or main.get_data(plr.Character)['canattack'] == false or main.get_data(plr.Character)['stunned'] == true then return end
db = true
spawn(function()
task.wait(dbtime)
db = false
end)
cooldowns.set_cd(plr, attack_name, cooldown)
table.clear(damaged)
stop = false
local char = plr.Character
local hrp = char.HumanoidRootPart
local hum = char.Humanoid
local animator = hum.Animator
local anim = animator:LoadAnimation(script.Parent.Parent.anims.use)
repeat wait() until anim.Length > 0
local acc = script.Parent.Parent.assets.peel_accessory:Clone()
acc.Parent = char
acc.Motor6D.Part0 = char['Right Arm']
acc.Motor6D.Part1 = acc
game.Debris:AddItem(acc, anim.Length)
anim:Play()
local windupt = tick()
game.ServerScriptService.game.events.stunned.Event:Connect(function(target)
if target == char and tick() - windupt <= windup then
stop = true
anim:Stop()
acc:Destroy()
return
end
end)
task.wait(windup)
hum.Health += heal
local touched = false
task.spawn(function()
local peel = script.Parent.Parent.assets.peel:Clone()
peel.CFrame = char['Right Arm'].CFrame
peel.Anchored = false
peel.Parent = workspace
peel.CollisionGroup = 'antiplayer'
game.Debris:AddItem(peel, duration)
local bv = Instance.new('BodyVelocity', peel)
bv.MaxForce = Vector3.new(math.huge, 0, math.huge)
bv.Velocity = hrp.CFrame.LookVector * -25
game.Debris:AddItem(bv, 0.1)
local ignore_names = {'peel', 'peel_accessory'}
peel.Touched:Connect(function(hit)
if touched == false then
local can_continue = true
if table.find(ignore_names, hit.Name) or hit.Parent == char then
can_continue = false
end
if can_continue == true then
touched = true
ts:Create(peel, TweenInfo.new(0.5), {Transparency = transparency}):Play()
local t = tick()
local loop;
loop = game["Run Service"].Heartbeat:Connect(function()
if tick() - t > duration or #damaged > 0 then
loop:Disconnect()
peel:Destroy()
return
else
for _, v_char in main.run_hitbox('radius', peel.CFrame, peel.Size.X / 2) do
if table.find(damaged, v_char) then else
table.insert(damaged, v_char)
main.hit_reg(v_char, char)
main.damage(v_char, char, damage)
main.stun(v_char, ragdolltime + 0.1)
main.knockback(v_char, v_char.HumanoidRootPart.CFrame.LookVector * -1, 15, 30, 0.05, ragdolltime)
end
end
end
end)
end
end
end)
end)
end)
note:
main.run_hitbox works through workspace:GetPartsBoundInBox
the script fires when a remoteevent is fired, which happens when the player presses the ‘e’ key
sorry for the messy code i made this in like 20 mins