EDIT: The code on the start is wrong, I forgot that my code will only show the force field to the player and not to everyone, so the new code is on the bottom of the post
First, you have to check if the player’s character has the tool inside of them. You can do it like this: (I will not put the full code so that you can learn some stuff for yourself)
Create a LocalScript inside StarterCharacterScript or anywhere you would like
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
-- Think of a way to put this if statement in a loop
if character:FindFirstChild(”ToolName”) then -- Replace ToolName with the name of your tool
-- Code here is what happens if the tool is equipped
else
-- Code here is what happens if tool is not equipped
end
Then clone the force field, parent it to the character, and weld it to the character. So to do this you would first need to add the force field into ReplicatedStorage. Then you can do this:
local forceFieldClone = game.ReplicatedStorage.ForceField:Clone()
forceFieldClone.Parent = character
local FFWeld = forceFieldClone.WeldConstraint -- Make sure there is a weld contraint inside the force field
FFWeld.Part0 = forceFieldClone
FFWeld.Part1 = character.HumanoidRootPart
Then you would add a touched event on the force field
So the code would be
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local killPlayer = game.ReplicatedStorage:WaitForChild(“KillPlayer”)
-- Think of a way to put this if statement in a loop
if character:FindFirstChild(”ToolName”) then -- Replace ToolName with the name of your tool
local forceFieldClone = game.ReplicatedStorage.ForceField:Clone()
forceFieldClone.Parent = character
local FFWeld = forceFieldClone.WeldConstraint -- Make sure there is a weld contraint inside the force field
FFWeld.Part0 = forceFieldClone
FFWeld.Part1 = character.HumanoidRootPart
forceFieldClone.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) and game.Players:FindFirstChild(hit.Parent.Name) then
killPlayer:FireServer(hit.Parent.Name)
end
end)
else
if forceFieldClone then
forceFieldClone:Destroy()
end
end
check if the player has a debounce value to prevent it from killing the player multiple times
local killPlayer = game.ReplicatedStorage:WaitForChild(“KillPlayer”)
killPlayer.OnServerEvent:Connect(function(player, targetName)
local targetPlayer = game.Players:FindFirstChild(targetName)
local targetCharacter = game.Workspace:FindFirstChild(targetName)
if targetCharacter then
if not targetCharacter:FindFirstChild(“Killed”) then
local killedVal = instance.new(“BoolValue”)
killedVal.Parent = targetCharacter
killedVal.Name = “Killed”
targetCharacter:FindFirstChild(“Humanoid”).Health = 0
end
end
end)
I haven’t tested out if this works though. Anyways, I didn’t put the whole code since I don’t want to spoonfeed. Hope this helps!
EDIT: The code before is wrong, I forgot that my code will only show the force field to the player and not to everyone, so here is the new code:
Insert a Script in ServerScriptService
game.Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
-- Think of a way to put this if statement in a loop
if character:FindFirstChild(”ToolName”) then -- Replace ToolName with the name of your tool
local forceFieldClone = game.ReplicatedStorage.ForceField:Clone()
forceFieldClone.Parent = character
local FFWeld = forceFieldClone.WeldConstraint -- Make sure there is a weld contraint inside the force field
FFWeld.Part0 = forceFieldClone
FFWeld.Part1 = character.HumanoidRootPart
forceFieldClone.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) and game.Players:FindFirstChild(hit.Parent.Name) then
local targetCharacter = game.Workspace:FindFirstChild(hit.Parent.Name)
if targetCharacter then
if not targetCharacter:FindFirstChild(“Killed”) then
local killedVal = instance.new(“BoolValue”)
killedVal.Parent = targetCharacter
killedVal.Name = “Killed”
targetCharacter:FindFirstChild(“Humanoid”).Health = 0
end
end
end
end)
else
if forceFieldClone then
forceFieldClone:Destroy()
end
end
Like I said, I’m not sure if it works since I haven’t tested it out for myself. This is just to guide you in the right direction.