Hey, guys. I am trying to make a localscript that creates a force field (spherical part) around a player when they press the "f" key. I am also trying to make it so that this force field damages any other players that touch it.
In the following script, I have successfully made the force field pop up around the player whenever they press "f":
Player = game.Players.LocalPlayer
mouse = Player:GetMouse()
db = false
function onKeyDown(key)
key = key:lower()
if db == false then
db = true
if key == "f" then -- when F is pressed...
--Make a little animation.
local RightShoulder = Player.Character.Torso["Right Shoulder"]
local LeftShoulder = Player.Character.Torso["Left Shoulder"]
local explosion = Instance.new("Part", game.Workspace)
explosion.Locked = true
explosion.Anchored = true
explosion.CanCollide = false
explosion.CFrame = Player.Character.Torso.CFrame
explosion.Transparency = 0.5
explosion.FormFactor = "Symmetric"
explosion.Size = Vector3.new(10,10,10)
explosion.Shape = "Ball"
explosion.BrickColor = BrickColor.new("Really red")
for i = 1,10 do
RightShoulder.C0 = RightShoulder.C0 * CFrame.Angles(0,0,0.5)
LeftShoulder.C0 = LeftShoulder.C0 * CFrame.Angles(0,0,-0.5)
explosion.Size = explosion.Size + Vector3.new(1.2,1.2,1.2)
wait(0.001)
end
for i = 1,10 do
RightShoulder.C0 = RightShoulder.C0 * CFrame.Angles(-0.5,0,0)
LeftShoulder.C0 = LeftShoulder.C0 * CFrame.Angles(-0.5,0,0)
wait(0.001)
end
for i = 1,10 do
RightShoulder.C0 = RightShoulder.C0 * CFrame.Angles(0.5,0,0)
LeftShoulder.C0 = LeftShoulder.C0 * CFrame.Angles(0.5,0,0)
wait(0.001)
end
for i = 1,10 do
RightShoulder.C0 = RightShoulder.C0 * CFrame.Angles(0,0,-0.5)
LeftShoulder.C0 = LeftShoulder.C0 * CFrame.Angles(0,0,0.5)
wait(0.001)
end
wait(3)
for i = 1,10 do
explosion.Transparency = explosion.Transparency + 0.1
wait(0.001)
end
explosion:Destroy()
end
db = false
end
end
mouse.KeyDown:connect(onKeyDown)
But now, I have no idea how to make it so that any other player that touches the force field gets damaged. Not killed. Only damaged.
If anyone could explain to me how to accomplish this, I would gladly appreciate it!
