I am looking on how to script basically an “anti-rdm” script. I have tried numerous times and each time I have tried it doesn’t work.
I am looking for a player to have a permanent forcefield except for when they equip a weapon. Once they unequip this weapon there is a wait(5) before the forcefield is added again.
Here is a crappy version I just made quickly…
This will add a force field when they spawn and will destroy when a tool is equipped and add after 5 seconds of it being unequipped
-- // Config
local AntiRDMDelay = 5 -- Must wait 5 seconds after they unequip to get the force field
-- // Declared Services
local Players = game:GetService("Players");
-- // rbxconnections
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
Instance.new("ForceField",Character)
Character.ChildAdded:Connect(function(Child)
if not Child:IsA("Tool") then return end
if Character:FindFirstChildOfClass("ForceField") then
Character:FindFirstChildOfClass("ForceField"):Destroy()
end
end)
Character.ChildRemoved:Connect(function(Child)
task.wait(AntiRDMDelay)
if not Character:FindFirstChildOfClass("ForceField") then
Instance.new("ForceField",Character)
end
end)
end)
end)