I am creating a anti-exploit for one of my games currently but I have this issue. I have a feeling it is because I have Filtering Enabled but I am not that sure.
Here is a part of my script that checks for a added forcefield
-- Checks for a added ForceField, game.Players.LocalPlayer.Character.ChildAdded:connect(function(obj) if (obj:IsA("ForceField")) then if (obj.Parent == game.Players.LocalPlayer.Character) then obj:Destroy() end end end)
Also, I am doing a fire script as well!
game.Players.LocalPlayer.Character.ChildAdded:connect(function(obj) if (obj:IsA("Fire")) then if (obj.Parent == game.Players.LocalPlayer.Character) then obj:Destroy() end end end)
It would be appreciated for someone to help with this problem! Once I get the answer, I'll confirm it! Also, I would love some tips on how to avoid problems like these if you can give some!
ChildAdded
is an extremely quick-reacting event. When you tried to destroy the object, it's parent was currently being changed. You have to wait before you can destroy it..
Also, you can combine these two events by using an or
statement in your condition.
connect
is deprecated! Use Connect
.local plr = game.Players.LocalPlayer --player local char = plr.Character or plr.CharacterAdded:Wait() --wait for character char.ChildAdded:Connect(function(obj) if obj:IsA("ForceField") or obj:IsA("Fire") then wait(.1) --wait a tiny bit obj:Destroy() end end)