0

# How do i make a forcefield block?

I want to make a block where whenever your touching it, it gives you a forcefield but when you get off of the block it goes away, this is my code

local forcePart = script.Parent

local canActivate = true

local function forceField(otherPart)

local humanoid = otherPart.Parent:FindFirstChild('Humanoid')

if humanoid and canActivate then

canActivate = false

forcePart.Transparency = 1

forcePart.CanCollide = false

local force = Instance.new('ForceField')

force.Parent = humanoid.Parent

wait(5)

forcePart.Transparency = 0

forcePart.CanCollide = true

force:Destroy()

canActivate = true

end

end

forcePart.Touched:Connect(forceField)