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.