The wall you showed us does several things.
- It detects when the player hits the wall
- It creates and animates a ball at the position in which it is hit
- It makes the player counteract the force of gravity
- It rag-dolls the player
- It sends the player away from the wall
I am not able to tell whether or it kills the player from the video. However, even so, I feel this can be left up to you.
Step #1: Detection
This one is actually simple. While the Touched
event isn’t that reliable, the wall is unmoving and the player doesn’t look to be moving that fast. Plus, other methods like Raycasting won’t work in this situation. So to set this you simply do something like this:
WallPart.Touched:Connect(function(hit)
local character = hit.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if humanoid and character:IsA("Model") then -- Detects if the hit part is part of a character character
-- Other code
end
end)
But wait! The Touched
event might fire multiple times for the same character! How do we prevent this? The solution is simple. We create a table of all the character who hit the wall and check if a character that hit the wall is already in the table.
local characters = {}
WallPart.Touched:Connect(function(hit)
local character = hit.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if humanoid and character:IsA("Model") and not table.find(characters, character) then -- Detects if the hit part is part of a character character
table.insert(characters, character)
-- Other code
end
end)
Step #2: Animation
For this step we want to create a ball that appears at the place of collision and then disappears. We want to use the characters torso position as the position of the hit. This way the ball is centered around the character. With the help of DebrisService
we can make the Ball disappear.
local Debris = game:GetService("Debris")
local function CreateEffect(position : Vector3)
local Ball = Instance.new("Part")
Ball.Shape = Enum.PartType.Ball
Ball.Color = Color3.new(0,1,1)
Ball.Material = Enum.Material.Neon
Ball.CanCollide = false
Ball.Anchored = true
Ball.Size = Vector3.new(5,5,5)
Ball.Position = position
Ball.Parent = workspace
Debris:AddItem(Ball,0.15)
end
CreateEffect(character.Torso.Position or character.UpperTorso.Position)
Step #3: Anti-Gravity
To accomplish Anti-Gravity on an assembly is an easy operation. Parent a BodyForce | Roblox Creator Documentation to the assembly RootPart
. Multiply the assemblies mass by the Workspace | Roblox Creator Documentation to get the counteractive force. Setting the Y-Value of BodyForce | Roblox Creator Documentation to the counteractive force will make the part achieve anti-gravity.
local function AntiGravity(assembly : BasePart)
local GravityForce = Vector3.new(0, assembly.AssemblyMass * workspace.Gravity, 0)
local BodyForce = Instance.new("BodyForce")
BodyForce.Force = GravityForce
BodyForce.Parent = assembly
end
AntiGravity(character:FindFirstChild("HumanoidRootPart"))
Step #4: Rag-Doll
This part is up to you. Ragdoll systems can be complicated because of the different rig types. Ragdoll the player, and also, if you want, kill them in this stage as well, after the joints have been set up. You’ll also want to make the players humanoid root part not able to collide.
Step #5: Fling
This part is easy. You simply get the relative position of the players using
local direction = WallPart.CFrame:PointToObjectSpace(character.HumanoidRootPart.Position)
character.HumanoidRootPart:ApplyImpulse(direction*100)