When the player touches the part, it creates a ForceField however, instead of creating one into the character it makes more. How would I prevent this from occurring?
Script that creates the forcefields when part is touched:
local WorkspaceService = game:GetService("Workspace")
local Safezone: BasePart = WorkspaceService.Safezone
local function OnTouch(OtherPart: BasePart)
local Character = OtherPart.Parent
local HumanoidRootPart: BasePart = Character:FindFirstChild("HumanoidRootPart")
if HumanoidRootPart then
local ForceField: ForceField = Instance.new("ForceField")
ForceField.Name = "SafezoneForceField"
ForceField.Visible = false
ForceField.Parent = Character
else
warn("Failed to find HumanoidRootPart!")
end
end
local function OnTouchEnd(OtherPart: BasePart)
local Character = OtherPart.Parent
local ForceField: ForceField = Character:FindFirstChildWhichIsA("ForceField")
if ForceField then
ForceField:Destroy()
end
end
Safezone.Touched:Connect(OnTouch)
Safezone.TouchEnded:Connect(OnTouchEnd)