Forcefield not removing on shop UI

Got an issue where whenever you enter the shop GUI it does put a forcefield on the character but then when the gui is disabled the forcefield stays on the player even though I do oldforcefield:Destroy()

Heres the script

local proximity = workspace.StuffShop.ShopStepin.ProximityPrompt 
local ProximityPromptService = game:GetService("ProximityPromptService")
local plr = game.Players.LocalPlayer
local character = plr.Character
local torso = character:WaitForChild("Torso")

proximity.Triggered:Connect(function() 
-- THIS IS WHERE THE FORCEFIELD GETS PUT INTO THE PLAYER	
	local GUI = script.Parent:WaitForChild("Shop Gui")
	GUI.Enabled = not GUI.Enabled
	torso.Anchored = true
	local forcefield = Instance.new('ForceField')
	forcefield.Parent = character
	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
	
	if GUI.Enabled == false then
		torso.Anchored = false
		local oldforcefield = character.WaitForChild("ForceField")
		oldforcefield:Destroy()
-- THIS IS WHEN THE OLD FORCEFIELD GETS DESTROYED
		game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,true)
	end
end)
1 Like

you used .WaitForChild instead of :WaitForChild

1 Like

it still isnt destroying???
ssssss

forcefield:Destroy() should work

correct me if i’m wrong but I’m pretty sure forcefields are server-sided only, and this appears to be running in a localscript

yeah i just noticed
sssssssssss

Is the Gui getting removed as well? I was just wondering if the if GUI.Enabled == false section is even getting called.

its only the instance thats getting removed, not the gui