Skip to content

Instantly share code, notes, and snippets.

@VegasCurie

VegasCurie/Chair

Created Jan 13, 2021
Embed
What would you like to do?
Code for a Chair
--Insert this into an empty tool in order for it to work no need to add a handle
local Fabriccolor = Color3.fromRGB(255,255,255)
local WoodColor = Color3.fromRGB(226,155,64)
local ChairCooldown = 62 -- time before a new box arrives
local ChairDespawnTime = 60 -- time before the chair removes itself
local ThrowVelocity = 150-- how fast the chair is thrown
local KnockBackDistance = 50 -- how far away the hit target is sent
local ChairPushDistance = 10 -- how far the chair pushes people back when held forward
local CriticalThreshold = .9 --the Threshold of velocity in which the chair stuns
local NormalDamage = 0 -- normal damage
local CriticalMultiplier = 0 -- crit multiplyer
script.Parent.CanBeDropped = false
-- Chair is used to push back killers. the box(this tool) deploys the chair.
-- the chair can be picked up by not holding a tool(allow people to stand on it)
-- other people can pick up the chair
-- using m1 will point the chairs legs forward pushing back humanoids a short distance
-- using m1 again will throw the chair knocking back whatever it hit.
-- the chairs knockback is based on its speed. if its near max velocity it will also stun the humanoid hit.
function ApplyWood(Part) -- reduce Number of lines
Part.Color = WoodColor
Part.Material = Enum.Material.WoodPlanks
end
function ApplyFabric(Part)
Part.Material = Enum.Material.Fabric
Part.Color = Fabriccolor
end
function ApplyWeld(Part1,Part2)
local WEld = Instance.new("WeldConstraint",Part1)
WEld.Part0 = Part1
WEld.Part1 = Part2
end
function MakeChair() -- create the chair
local ChairModel = Instance.new("Model")
local CBLeL = Instance.new("Part",ChairModel)
CBLeL.Size = Vector3.new(0.25, 1.75, 0.25)
CBLeL.Position = Vector3.new(-0.875, -1, 0.875)
CBLeL.Orientation = Vector3.new(-10, 0, 0)
CBLeL.Name = "CBLeL"
ApplyWood(CBLeL)
local CBLS = Instance.new("Part",ChairModel)
CBLS.Size = Vector3.new(1.5, 0.25, 0.25)
--no need for orientation
CBLS.Position = Vector3.new(0, -0.25, 0.625)
CBLS.Name = "CBLS"
ApplyWood(CBLS)
local CBRBLe = Instance.new("Part",ChairModel)
CBRBLe.Size = Vector3.new(0.25, 1.75, 0.25)
CBRBLe.Position = Vector3.new(0.875, 0.709, 0.95)
CBRBLe.Orientation = Vector3.new(10, 0, 0)
CBRBLe.Name = "CBRBLe"
ApplyWood(CBRBLe)
local CBRBM = Instance.new("Part",ChairModel)
CBRBM.Size = Vector3.new(0.25, 1.75, 0.25)
CBRBM.Orientation = Vector3.new(10,0,0)
CBRBM.Position = Vector3.new(-0.025, 0.654, 1.034)
CBRBM.Name = "CBRBM"
ApplyWood(CBRBM)
local CBRBRi = Instance.new("Part",ChairModel)
CBRBRi.Size = Vector3.new(0.25, 1.75, 0.25)
CBRBRi.Position = Vector3.new(-0.875, 0.709, 0.95)
CBRBRi.Orientation = Vector3.new(10, 0, 0)
CBRBRi.Name = "CBRBRi"
ApplyWood(CBRBRi)
local CBRiL = Instance.new("Part",ChairModel)
CBRiL.Size = Vector3.new(0.25, 1.75, 0.25)
CBRiL.Position = Vector3.new(0.875, -1, 0.875)
CBRiL.Orientation = Vector3.new(-10, 0, 0)
CBRiL.Name = "CBRiL"
ApplyWood(CBRiL)
local CFLeL = Instance.new("Part",ChairModel)
CFLeL.Size = Vector3.new(0.25, 1.75, 0.25)
CFLeL.Position = Vector3.new(-0.875, -1, -0.875)
CFLeL.Orientation = Vector3.new(10, 0, 0)
CFLeL.Name = "CFLeL"
ApplyWood(CFLeL)
local CFLS = Instance.new("Part",ChairModel)
CFLS.Size = Vector3.new(1.5, 0.25, 0.25)
--no need for orientation
CFLS.Position = Vector3.new(0, -0.25, -0.625)
CFLS.Name = "CFLS"
ApplyWood(CFLS)
local CFRiL = Instance.new("Part",ChairModel)
CFRiL.Size = Vector3.new(0.25, 1.75, 0.25)
CFRiL.Orientation = Vector3.new(10, 0, 0)
CFRiL.Position = Vector3.new(0.875, -1, -0.875)
CFRiL.Name = "CFRiL"
ApplyWood(CFRiL)
local CLeCS = Instance.new("Part",ChairModel)
CLeCS.Size = Vector3.new(0.25, 0.75, 0.25)
--no need for orientation
CLeCS.Position = Vector3.new(-0.875, 1.948, 1.08)
CLeCS.Name = "CLeCS"
ApplyWood(CLeCS)
local CLeLS = Instance.new("Part",ChairModel)
CLeLS.Size = Vector3.new(0.25, 0.25, 1.5)
--no need for orientation
CLeLS.Position = Vector3.new(-0.875,-0.25,0)
CLeLS.Name = "CLeLS"
ApplyWood(CLeLS)
local CLC = Instance.new("Part",ChairModel)
CLC.Size = Vector3.new(1.5, 0.25, 1.5)
--no Orientation
CLC.Position = Vector3.new(0,0.25,0)
CLC.Name = "CLC"
ApplyFabric(CLC)
local CLCS = Instance.new("Part",ChairModel)
CLCS.Size = Vector3.new(2, 0.25, 0.25)
--no Orientation
CLCS.Position = Vector3.new(0,1.448,1.08)
CLCS.Name = "CLCS"
ApplyWood(CLCS)
local CHAIRMAIN = Instance.new("Part",ChairModel)
CHAIRMAIN.Size = Vector3.new(2, 0.25, 2)
--no Orientation
CHAIRMAIN.Position = Vector3.new(0,0,0)
CHAIRMAIN.Name = "CHAIRMAIN"
ApplyWood(CHAIRMAIN)
local CRiCS = Instance.new("Part",ChairModel)
CRiCS.Size = Vector3.new(0.25, 0.75, 0.25)
--no Orientation
CRiCS.Position = Vector3.new(0.875, 1.948, 1.08)
CRiCS.Name = "CRiCS"
ApplyWood(CRiCS)
local CRiLS = Instance.new("Part",ChairModel)
CRiLS.Size = Vector3.new(0.25, 0.25, 1.5)
--no Orientation
CRiLS.Position = Vector3.new(0.875, -0.25, 0)
CRiLS.Name = "CRiLS"
ApplyWood(CRiLS)
local ChairUpperCushion = Instance.new("Part",ChairModel)
ChairUpperCushion.Size = Vector3.new(2.5, 1.75, 0.25)
--no Orientation
ChairUpperCushion.Position = Vector3.new(0, 2.198, 0.58)
ChairUpperCushion.Name = "ChairUpperCushion"
ApplyFabric(ChairUpperCushion)
local ChUpCuHo = Instance.new("Part",ChairModel)
ChUpCuHo.Size = Vector3.new(2, 1.5, 0.25)
--no Orientation
ChUpCuHo.Position = Vector3.new(0, 2.073, 0.83)
ChUpCuHo.Name = "ChUpCuHo"
ApplyWood(ChUpCuHo)
local ChUpCuSu = Instance.new("Part",ChairModel)
ChUpCuSu.Size = Vector3.new(2, 0.25, 0.25)
--no orientation
ChUpCuSu.Position = Vector3.new(0, 2.448, 1.08)
ChUpCuSu.Name = "ChUpCuSu"
ApplyWood(ChUpCuSu)
ApplyWeld(CHAIRMAIN,CBLeL)
ApplyWeld(CHAIRMAIN,CBLS)
ApplyWeld(CHAIRMAIN,CBRBLe)
ApplyWeld(CHAIRMAIN,CBRBM)
ApplyWeld(CHAIRMAIN,CBRBRi)
ApplyWeld(CHAIRMAIN,CBRiL)
ApplyWeld(CHAIRMAIN,CFLeL)
ApplyWeld(CHAIRMAIN,CFLS)
ApplyWeld(CHAIRMAIN,CFRiL)
ApplyWeld(CHAIRMAIN,CLeCS)
ApplyWeld(CHAIRMAIN,CLeLS)
ApplyWeld(CHAIRMAIN,CLC)
ApplyWeld(CHAIRMAIN,CLCS)
ApplyWeld(CHAIRMAIN,CRiCS)
ApplyWeld(CHAIRMAIN,CRiLS)
ApplyWeld(CHAIRMAIN,ChairUpperCushion)
ApplyWeld(CHAIRMAIN,ChUpCuHo)
ApplyWeld(CHAIRMAIN,ChUpCuSu)
ChairModel.PrimaryPart = CHAIRMAIN
return ChairModel
end
local Thrown = false
function ThrowChair(Chair,ChairTool,OwnerHumanoid,LookDirection)
Thrown = true
local Animation = Instance.new("Animation",Chair)
Animation.AnimationId = "http://www.roblox.com/Asset?ID=31020869"--barrel throw
local Attackani = OwnerHumanoid:LoadAnimation(Animation)
Attackani:Play()
Attackani:AdjustSpeed(2.5)
OwnerHumanoid:UnequipTools()--force unequip
local Main = Chair:WaitForChild("CHAIRMAIN")
local ChairHitbox = Instance.new("Part",Chair)
ChairHitbox.Name = "Hitter"
ChairHitbox.Transparency = 1
ChairHitbox.Size = Vector3.new(2.5,6,2.5)
ChairHitbox.CanCollide = false
ChairHitbox.Massless = true
ChairHitbox.CFrame = Main.CFrame
local weld = Instance.new("WeldConstraint",ChairHitbox)
weld.Part1 = ChairHitbox
weld.Part0 = Main
ChairHitbox.Touched:connect(function(hit)
OnChairHit(Chair,hit,LookDirection,OwnerHumanoid)
end)
Main.Velocity = LookDirection*(ThrowVelocity)
end
local ChairForwardNorm = Vector3.new(0, -1, -0.007)
local ChairForwardpos = Vector3.new(1, 3, 0)
function SwitchGrip(ChairTool)
if ChairTool.GripPos ~= ChairForwardpos then
ChairTool.GripForward = ChairForwardNorm
ChairTool.GripPos = ChairForwardpos
return "Switched"
end
ChairTool.GripForward = Vector3.new(0,0,-1)
ChairTool.GripPos = Vector3.new(0,0,0)
return "Returned"
end
local ChairHit = false
function OnChairHit(Chair,Hit,Look,Owner)
if Chair and ChairHit == false then
if Hit and Hit.Parent then
local Humanoid = Hit.Parent:FindFirstChildOfClass("Humanoid")
if Humanoid == nil and Hit.Parent.Parent then
Humanoid = Hit.Parent.Parent:FindFirstChildOfClass("Humanoid")
if Humanoid == nil and Hit.Parent.Parent.Parent then
Humanoid = Hit.Parent.Parent.Parent:FindFirstChildOfClass("Humanoid")
end
end
if Humanoid and Humanoid~=Owner then
ChairHit = true
local Main = Chair:WaitForChild("CHAIRMAIN")
local ChairBreak = Instance.new("Sound")
ChairBreak.SoundId = "rbxassetid://158712406"
ChairBreak.Parent = Main
ChairBreak.Playing = true
local mainvel= Main.Velocity.Magnitude
local div = (mainvel/ThrowVelocity)
Main:BreakJoints()
print("Hit ",Hit)
local distance = div*KnockBackDistance -- push them very far away depending on the chairs velocity
local duration = 0.3 -- longer duration holds hit target back for longer
local speed = distance/duration
local velocity = Look * speed
local shoveForce = Instance.new("BodyVelocity")
shoveForce.maxForce = Vector3.new(9e9, 9e9, 9e9)
shoveForce.velocity = velocity
shoveForce.Parent = Hit
game:GetService("Debris"):AddItem(shoveForce, duration)
if div>= .5 then -- Crit FORCE
print("CRIT")
script.Parent = Humanoid
local ChairCrit = Instance.new("Sound")
ChairCrit.SoundId = "rbxassetid://296102734"
ChairCrit.Parent = Hit
ChairCrit.Volume = 3
ChairCrit.Playing = true
game:GetService("Debris"):AddItem(ChairCrit, 10)
Humanoid:TakeDamage(NormalDamage*CriticalMultiplier)
Humanoid.PlatformStand = true
Hit.RotVelocity = Hit.RotVelocity+Vector3.new(math.random(-100,100),math.random(-100,100),math.random(-100,100)) --trip em up
wait(1)
Humanoid.PlatformStand = false
script:Destroy()--stun
else
Humanoid:TakeDamage(NormalDamage*div)
end
end
end
end
end
if script:FindFirstChild("CooldownMarker") ~= nil then
wait(ChairCooldown)
else
local Cooldown = Instance.new("BoolValue",script)
Cooldown.Name = "CooldownMarker"
end
local ChairDeployerTool = script.Parent
local ClonedVariant = ChairDeployerTool:Clone()
local Holder = ChairDeployerTool.Parent:FindFirstChild("Humanoid")
if Holder then
Holder:UnequipTools() -- ensures the box isn't meshed with anything
end
local BoxHandle = Instance.new("Part",ChairDeployerTool)
BoxHandle.Name = "Handle"
BoxHandle.Size = Vector3.new(2,1,2)
local BoxDecal = Instance.new("Decal",BoxHandle)
BoxDecal.Face = "Top"
BoxDecal.Texture = "http://www.roblox.com/asset/?id=16791877" -- replace with what you want.
BoxHandle.Color = Color3.fromRGB(239, 184, 56)
if Holder then
ChairDeployerTool.Parent = Holder.Parent -- ensures the box is properly held
end
local ChairHeld = false
local Players = game:GetService("Players")
ChairDeployerTool.Activated:Connect(function()--this is for deploying
local ChairModel = MakeChair()
ChairModel.Parent = workspace
ChairModel:SetPrimaryPartCFrame(BoxHandle.CFrame)
script.Parent = ChairModel
ClonedVariant.Parent = ChairDeployerTool.Parent
ChairDeployerTool:Destroy()
local current_chairtool
local TimeCreated = time()
game:GetService("Debris"):AddItem(ChairModel,ChairDespawnTime)
local function MakeEquipable() -- handles making the chair incapable of being put in the users backpack
if Thrown == true then return end
current_chairtool = Instance.new("Tool",ChairModel)
current_chairtool.Name = "Chair"
game:GetService("Debris"):AddItem(current_chairtool,ChairDespawnTime-(time()-TimeCreated))--ensures simultenius erasure
local Main = ChairModel:WaitForChild("CHAIRMAIN")
local ChairToolHandle = Instance.new("Part",current_chairtool)
ChairToolHandle.Name = "Handle"
ChairToolHandle.Transparency = 1
ChairToolHandle.Size = Vector3.new(2.5,5.5,2.5)
ChairToolHandle.CanCollide = false
ChairToolHandle.CFrame = Main.CFrame
local weld = Instance.new("WeldConstraint",ChairToolHandle)
weld.Part1 = ChairToolHandle
weld.Part0 = ChairModel.PrimaryPart
local ChairEquiped = false
local Switched = false
local HoldingHuman = nil
local ActivationCon
local UnequipCon
local EquipConnection
EquipConnection = ChairToolHandle.Touched:connect(function(Equiper)
if Equiper and Equiper.Parent then
local Player = Players:GetPlayerFromCharacter(Equiper.Parent)
local Humanoid = Equiper.Parent:FindFirstChild("Humanoid")
local Tool = Equiper.Parent:FindFirstChildOfClass("Tool") -- so people can stand on it if they want too
if Player ~= nil and Humanoid and Humanoid.Health > 0 and Tool == nil and ChairEquiped ==false then
Humanoid:UnequipTools()
HoldingHuman = Humanoid
current_chairtool.Parent = Equiper.Parent
-- EquipConnection:Disconnect()
ChairEquiped = true
elseif Humanoid and Humanoid.Health > 0 and ChairEquiped ==true and Switched == true then
local Looker = HoldingHuman.Parent:FindFirstChild("HumanoidRootPart")
if Looker then
local Look = Looker.CFrame.LookVector
local distance = 10
local duration = 0.15
local speed = distance/duration
local velocity = Look * speed
local shoveForce = Instance.new("BodyVelocity")
shoveForce.maxForce = Vector3.new(1e9, 1e9, 1e9)
shoveForce.velocity = velocity
shoveForce.Parent = Equiper
game:GetService("Debris"):AddItem(shoveForce, duration)
end
end
end
end)
UnequipCon = current_chairtool.Unequipped:Connect(function()
UnequipCon:Disconnect()
ActivationCon:Disconnect()
EquipConnection:Disconnect()
game:GetService("Debris"):AddItem(current_chairtool,0) -- bypasses attempting to destroy an object changing parents
ChairEquiped = false
wait(1)
MakeEquipable()
end)
ActivationCon = current_chairtool.Activated:connect(function()
local Looker = HoldingHuman.Parent:FindFirstChild("HumanoidRootPart")
local res = SwitchGrip(current_chairtool)
Switched = true
if res ~= "Switched" then
ActivationCon:Disconnect()
EquipConnection:Disconnect()
ThrowChair(ChairModel,current_chairtool,HoldingHuman,Looker.CFrame.LookVector)--SwitchGrip(current_chairtool)Chair,ChairTool,OwnerHumanoid,LookDirection
end
end)
end
wait(1)
MakeEquipable()
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment