---(Lightsaber script, only local script that has to do with the physical lightsaber)
wait() -- settings on different styles and blocking
local attackticket = 0
local ibor = 0
local Touches = 0
local LastDmg = 0
local lasthit = false
local lunging = false
local ochanging = false
local ibo = false
local corew = true
local Tool = script.Parent
local Slash = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Slash)
local Lunge = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Lunge)
local Blade = Tool:findFirstChild("BladeReal")
local Bladept = Tool:findFirstChild("Bladept")
local Inner1 = Bladept.Inner
local Inner2 = Bladept.Inner2
local Inner3 = Bladept.Inner3
local Inner4 = Bladept.Inner4
local Outer1 = Bladept.Outer
local Outer2 = Bladept.Outer2
local Outer3 = Bladept.Outer3
local Outer4 = Bladept.Outer4
Inner1.Enabled = false
Inner2.Enabled = false
Inner3.Enabled = false
Inner4.Enabled = false
Outer1.Enabled = false
Outer2.Enabled = false
Outer3.Enabled = false
Outer4.Enabled = false

local function ChangeColor(NBlade, aBColor)
	local aColor = BrickColor.new(aBColor).Color
	if NBlade == 1 then
		Inner1.Color = ColorSequence.new(aColor)
		Inner2.Color = ColorSequence.new(aColor)
		Inner3.Color = ColorSequence.new(aColor)
		Inner4.Color = ColorSequence.new(aColor)
	else
		Outer1.Color = ColorSequence.new(aColor)
		Outer2.Color = ColorSequence.new(aColor)
		Outer3.Color = ColorSequence.new(aColor)
		Outer4.Color = ColorSequence.new(aColor)
	end
end

Blade.Touched:connect(function(Hit)
	if Hit.Name:sub(1,5) == "Blade" and Hit.Parent:findFirstChild("Lightsaber") and Hit.Friction == 1 then
		Touches = Touches+1
		local TEnd = false
		local BTEC = Blade.TouchEnded:connect(function (Hit2)
			if Hit2 == Hit and not TEnd then
				TEnd = true
				wait(.2)
				Touches = Touches-1
				if Touches < 0 then
					Touches = 0
				end
			end
		end)
		local Roll = math.random(2)
		Tool.Handle:findFirstChild("hit"..tostring(Roll)):play()
		while not TEnd do
			wait(1)
			if (Hit.Position - Blade.Position).magnitude > 4.8 or not Tool:IsDescendantOf(workspace) or not Hit:IsDescendantOf(workspace) then
				TEnd = true
				wait(.2)
				Touches = Touches-1
				if Touches < 0 then
					Touches = 0
				end
			end
		end
	elseif Touches == 0 and workspace.DistributedGameTime - LastDmg > .15 then
		local Humanoid = Hit.Parent and Hit.Parent:findFirstChild("Humanoid")
		if Humanoid and Humanoid:IsA("Humanoid") then
			LastDmg = workspace.DistributedGameTime
			Humanoid:TakeDamage(20)
		end
	end
end)

game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(Key)
	if Tool.Parent == game.Players.LocalPlayer.Character then
		if Key == "q" and not ochanging then
			if ibo then
				ochanging = true
				Tool.Handle.deactivate:play()
				Inner1.Enabled = false
				Inner2.Enabled = false
				Inner3.Enabled = false
				Inner4.Enabled = false
				Outer1.Enabled = false
				Outer2.Enabled = false
				Outer3.Enabled = false
				Outer4.Enabled = false
				local BladeWeld = Bladept:findFirstChild("ToolWeld")
				if BladeWeld then
					BladeWeld.C0 = CFrame.new(0, 6.6, 0)*CFrame.Angles(0,0,math.rad(180))
				end
				wait(.5)
				Tool.Handle.loop:stop()
				Tool.Handle.loop2:stop()
				Blade.Friction = 0
				ibo = false
				ochanging = false
			else
				ochanging = true
				Tool.Handle.activate:play()
				Tool.Handle.loop:play()
				Inner1.Enabled = true
				Inner2.Enabled = true
				Inner3.Enabled = true
				Inner4.Enabled = true
				Outer1.Enabled = true
				Outer2.Enabled = true
				Outer3.Enabled = true
				Outer4.Enabled = true
				local BladeWeld = Bladept:findFirstChild("ToolWeld")
				if BladeWeld then
					BladeWeld.C0 = CFrame.new(0, 0, 0)
				end
				wait(.5)
				Tool.Handle.loop2:play()
				Blade.Friction = 1
				ibo = true
				ochanging = false
			end
		elseif Key == "e" then
			corew = not corew
			if corew then
				ChangeColor(1,"Institutional white")
			else
				ChangeColor(1,"Really black")
			end
		elseif Key == "r" then
			ChangeColor(2, "Really red")
		elseif Key == "z" then
			ChangeColor(2, "Really black")
		elseif Key == "x" then
			ChangeColor(2, "Institutional white")
		elseif Key == "c" then
			ChangeColor(2, "Cyan")
		elseif Key == "h" then
			ChangeColor(2, "Medium stone grey")
		elseif Key == "b" then
			ChangeColor(2, "Bright blue")
		elseif Key == "v" then
			ChangeColor(2, "Pastel green")
		elseif Key == "g" then
			ChangeColor(2, "Lime green")
		elseif Key == "y" then
			ChangeColor(2, "New Yeller")
		elseif Key == "u" then
			ChangeColor(2, "Deep orange")
		elseif Key == "m" then
			ChangeColor(2, "Magenta")
		elseif Key == "n" then
			ChangeColor(2, "Navy blue")
		elseif Key == "p" then
			ChangeColor(2, "Dark indigo")
		end
	end
end)

Tool.Activated:connect(function()
	if ibo then
		if lasthit == false then
			attackticket = attackticket+1
			local ticket=attackticket
			Tool.Handle.slash:play()
			lasthit = true
			wait(0.35)
			if ticket == attackticket then
				lasthit = false
			end
			Tool.GripUp = Vector3.new(0, 1, 0)
			Tool.GripRight = Vector3.new(1, 0, 0)
			Tool.GripPos = Vector3.new(0, 0.3, 0)
			Tool.GripForward = Vector3.new(-0, -0, -1)
		end
	end
end)

Tool.Unequipped:connect(function()
	Tool.Handle.loop:stop()
	Tool.Handle.loop2:stop()
end)

Tool.Equipped:connect(function()
	if ibo then
		Tool.Handle.loop:play()
		Tool.Handle.loop2:play()
	end
end)

1 comment

0

Well there is alot rong with your script first of all you cant do tuched events in local scripts if i remember that right second of all you need to make a remote even t