Creating ForceField after player imput

I want to apply “ForceField” effect after input at players character.

But I can’t figure out how to, for some reason I can’t make instance that would make it happen.

I was lurking around the internet, dev forum, and dev Hub for answers and it still doesn’t work.

Could someone explain to me how this bloody thing works !?

Hi, luckily I was making things with creating ForceFields yesterday. Here’s the ForceField creation Code:
Instance.new("ForceField", player.Character)

1 Like

Aight, figured it out, here is my full script.

local Debris = game:GetService("Debris")
local UIS = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local character = player.Character

debounce = false

local function giveForcefield()
	local FF=Instance.new("ForceField")
	FF.Visible=false
	FF.Parent=character
	Debris:AddItem(FF, 10)
end

local function Input(input, gameProcessedEvent)
	if debounce then return end 
	if UIS:IsKeyDown(Enum.KeyCode.E) then debounce = true		
	print("shield on")
	   giveForcefield() debounce = false
	end	
end
UIS.InputBegan:Connect(Input)

Code was not working because i thought that having special commands in Instance.new(“ForceField”, “random stuff”) was a requirement but no it works like any other instance.
Dumb me

It happens to everyone. If you want to you can also name your ForceField:

local ForceField = Instance.new("ForceField", player.Character)
ForceField.Name = "NewForceField"

or more reliable method:

local ForceField = Instance.new("ForceField")
ForceField.Name = "NewForceField"
ForceField.Parent = player.Character

You’re probably asking why should I name my ForceField? My answer is: to destroy it later.
Example: Player spawns. Spawnpoint gives him ForceField called ‘ForceField’ and you give him ForceField with a name ‘NewForceField’. Now if you want you can destroy your ForceField without confusing the Script. I hope that you know what’s I’m talking about.

4 Likes