Step 1: Creating the Barrel
You Tube Video – Creating the Barrel
Written Instruction
Create a cylinder, name it “Barrel”, rotate it so that it can roll on the ground, and make its size: (6,12,3)
Give it the texture “Wood Plank” and the Brickcolor “CGA Brown”.
Under Properties, enable the Barrel’s CustomPhysicalProperties and set the following setttings:
:– | :–
Density | 100
Elasticity | 0
ElasticityWeight | 100
Friction | 0.2
FrictionWeight | 100
Create a ramp, and place the barrel on top of it. Make sure to delete any welds between the ramp and the barrel. If the barrel rolls down and continues moving, you can move on to the next step.
Now we need to make it so that the barrel explodes when it touches a player or another barrel.
Create a wall directly infront of the barrel’s path called “Delete”. Any barrel touching this will be destroyed. Color this wall a distingue color.
Create a script named “Explode” under the barrel.
Explode
local Barrel = script.Parent --[[ When the barrel is touched by either a player or another barrel, the script does the ff: Creates an explosion on the barrel's current position (with the intention of killing the player) Destroys the barrel If the barrel touches the end of the course ("Delete"), the barrel is deleted to not waste computer performance on useless objects. --]] Barrel.Touched:Connect(function(otherPart) if otherPart.Parent:FindFirstChildOfClass("Humanoid") or otherPart.name == "Barrel" then local Explosion = Instance.new ("Explosion", Barrel) Explosion.Parent = Barrel local BarrelPivot = Barrel:GetPivot() Explosion.Position = Vector3.new (BarrelPivot.X, BarrelPivot.Y, BarrelPivot.Z) Explosion.BlastPressure = 50 Explosion.BlastRadius = 5 Explosion.ExplosionType = Enum.ExplosionType.NoCraters wait(0.5) Barrel:Destroy() else if otherPart.name == "Delete" then Barrel:Destroy() end end end)
Now that your done with the script, make sure that the barrel explodes when you or another player touches it. Also test if the barrel is destroyed when it touches the “Delete” wall.
In your obstacle course, the barrel can sometimes stop and stay in place. To prevent this obstacle from hindering the gaming-experience, we will implement a system where the barrel explodes if it is not moving.
Create a script under barrel called “Timer”
Timer
local Barrel = script.Parent local SavedPosition = Barrel.Position --[[ The timer code prevents barrels from being completely stationary for long periods of time. Stationary barrels block the player's path and hinders the gaming experience. Every second, checks if the barrel is moving. It does this by checking if the barrel's current position is equal to its position 2 seconds ago. Once it does this, it does the ff: A loop that lasts 100 steps changes the barrel's color from red to brown to red again repeatedly. The interval between each color change gets smaller as more steps occur. After these steps have passed, an explosion is created on top of the barrel and destroys it shortly after. --]] while wait(1) do SavedPosition = Barrel.Position wait (2) if SavedPosition == Barrel.Position then for i=1, 100, 1 do wait (0.05-(i*0.005)) if Barrel.Color ~= Color3.new(1, 0, 0) then Barrel.Color = Color3.new(1, 0, 0) else Barrel.Color = Color3.new(0.415686, 0.223529, 0.0352941) end end local Explosion = Instance.new ("Explosion", Barrel) local Pivot = Barrel:GetPivot() Explosion.Parent = Barrel Explosion.Position = Vector3.new (Pivot.X,Pivot.Y,Pivot.Z) Explosion.BlastPressure = 50 Explosion.BlastRadius = 5 Explosion.ExplosionType = Enum.ExplosionType.NoCraters wait (0.5) Barrel:Destroy() else --print ("RecentMovement = True") end end
Test if the barrel explodes if it is standing still. If it is, you are done creating the barrel! Now we need to create a mechanism that spawns multiple