How do I make when a player presses a keycode they receive a forcefield
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input)
if input.Keycode == Enum.KeyCode.X then
-- The forcefield giver code
end
end)
local UserInputService = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
UserInputService.InputBegan:Connect(function(input)
if input.Keycode == Enum.KeyCode.X then
-- The forcefield giver code
local new = instance.new("Forcefield")
new.Parent = plr
end
end)
You’ll have to make use of RemoteEvents and a Server Script.
Once the player presses the Key, an event should fire and tell the server to provide him with a forcefield. If you do that locally, the forcefield won’t be visible to other players and the person themselves can still be damaged.
If you’re unsure on how to create this, I suggest the following materials:
I really suggest you read the materials I’ve provided you with and attempt to create something by yourself. If you just copy and paste code you won’t be able to learn for yourself! Study the links I’ve provided you and I’m 100% sure you’ll be able to assemble this on your own.