Hi, IDK what’s going on but every time I shot at somebody in my datestone with a forcefield, it gets removed. This is the code I’m using currently… but I can’t come up with ideas.
local hitbox = script.Parent
hitbox.Touched:Connect(function(touch)
if touch.Parent:FindFirstChild(“Humanoid”) and touch.Parent:FindFirstChild(“Safezone Protection”) == nil then
local Forcefield = Instance.new(“ForceField”)
Forcefield.Name = “Safezone Protection”
Forcefield.Visible = true
Forcefield.Parent = touch.Parent
end
end)
hitbox.TouchEnded:Connect(function(touch)
if touch.Parent:FindFirstChild(“Humanoid”) and touch.Parent:FindFirstChild(“Safezone Protection”) ~= nil then
touch.Parent:FindFirstChild(“Safezone Protection”):Destroy()
end
end)
local hitbox = script.Parent
hitbox.Touched:Connect(function(touch)
if touch.Parent:FindFirstChild("Humanoid") and touch.Parent:FindFirstChild("Safezone Protection") == nil then
local Forcefield = Instance.new("ForceField")
Forcefield.Name = "Safezone Protection"
Forcefield.Visible = true
Forcefield.Parent = touch.Parent
end
end)
hitbox.TouchEnded:Connect(function(touch)
if touch.Parent:FindFirstChild("Humanoid") and touch.Parent:FindFirstChild("Safezone Protection") ~= nil then
touch.Parent:FindFirstChild("Safezone Protection"):Destroy()
end
end)
that helped out a lot, however, I’m struggling to try to detect when the player has left the zone to remove the forcefield. any help? thanks!
local Part = script.Parent
local Size = Part.Size
local Region = Region3.new(Part.Position-(Size/2),Part.Position+(Size/2))
while true do
wait()
local partsInRegion = workspace:FindPartsInRegion3(Region, nil,1000)
for i, part in pairs(partsInRegion) do
local char = part.Parent
if part.Parent:FindFirstChild("Humanoid") ~= nil and char:FindFirstChild("Safezone Protection") == nil then
local Forcefield = Instance.new("ForceField")
Forcefield.Name = "Safezone Protection"
Forcefield.Visible = true
Forcefield.Parent = char
end
end
end
Well I fixed it with a bit of imagination haha. I said well why not mixing region 3 and touch ended? and there u have it… the perfect combination! thx for ur help!
You can add a table of players that are currently inside the region3, for instance, every time you scan the region3 and find a player, you add the player to the table if they aren’t already. In future scans, check the table to see if the player in the table is still inside the region3, and if not, remove the forcefield. I don’t like TouchEnded very much since it can get buggy