Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ForceField = Instance.new("ForceField")
local FocusedEvent = ReplicatedStorage:WaitForChild("Focused")
local UnFocusedEvent = ReplicatedStorage:WaitForChild("Unfocused")
local function createforcefiled(player)
local Forcefield = Instance.new("ForceField")
Forcefield.Visible = true
Forcefield.Parent = player.Character
for _, v in player.Character:GetDescendants() do
if v:IsA("MeshPart") then
v.Material = Enum.Material.ForceField
end
end
end
local function removeforcefield(player)
player.Character.Forcefield:Destory()
for _, v in player.Character:GetDescendants() do
if v:IsA("MeshPart") then
v.Material = Enum.Material.Plastic
end
end
end
FocusedEvent.OnServerEvent:Connect(function(player)
removeforcefield(player)
end)
UnFocusedEvent.OnServerEvent:Connect(function(player)
createforcefiled(player)
end)
(that script is in server script service)
(The next script is in StarterPlayerScripts)
local InputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FocusedEvent = ReplicatedStorage:WaitForChild("Focused")
local UnFocusedEvent = ReplicatedStorage:WaitForChild("Unfocused")
InputService.WindowFocused:Connect(function()
FocusedEvent:FireServer()
end)
InputService.WindowFocusReleased:Connect(function()
UnFocusedEvent:FireServer()
end)
The error:
Infinite yield possible on 'ReplicatedStorage:WaitForChild("Focused")'```
** You are now Level 5! **