You can write your topic however you want, but you need to answer these questions:
-
Whilst in Dual mode I want the back blades to enable (Blade2 and its emitters) The lightsabers have three modes. Dual, Single and Double. I’m trying to make a dual double lightsabers which means you have two double lightsabers. One in each hand. You will be able to find the main code on line 255. It fires for each blade when the lightsaber is toggled.
-
What is the issue? Include screenshots / videos if possible!
It only toggles the front two emitters rather than toggling all 4. (Can’t find blade 2) -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried findfirstchild for the 2nd blade pair but I’m not that great at LUA so I don’t know if I targetted it.
local emitter2 = script.parent.parent.bin.Blade2.Emitter2.Outer
emitter2.Enabled = true
13:59:58.526 - bin is not a valid member of Model.
We then put it in a separate script which worked. However it meant that they weren’t linked with the client side input began
Checked the path twice.
And the code also broke the toggle for the front.
https://i.gyazo.com/thumb/1200/c6d83bfbe0e796f10de628c2ecaac066-png.jpg
https://gyazo.com/6f5e117a7d503d2d460fda33e0335d7b
The lightsabers are open source by SolarHorizon.
https://www.roblox.com/games/421446972/lightsabers-open-source
The script is 600 lines long so it’d probably be better if you had it in studio.
TalentedValorius#0084
First post!
I’m a beginner so forgive any mistakes. :3
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
--// SolarHorizon - S: 8/22/2016 ~ C: 10/6/2016
-->> Let's try this again
local Tool = script.Parent.Parent
local user = Tool.Parent.Parent
repeat wait() until user.Character
local event = script.Parent.Event
local Module = require(script.Parent.Module)
local Human = user.Character:FindFirstChild("Humanoid")
--local Saber = Tool.bin
local Vibro = script.Parent.Type.Value == "Vibro"
local Dual = script.Parent.Type.Value == "Dual"
local ActiveBlades
local ActiveSabers
local Igniting
local CanDamage
local Ingited
local block
local Damage = 20
local Unarmed = 1.5 -- Unarmed damage multiplier
local BeltPos = {
[1] = CFrame.new(-0.8,-1,-0.6) * CFrame.fromEulerAnglesXYZ(math.rad(180),math.rad(180),math.rad(-5)),
[2] = CFrame.new(0.8,-1,-0.6) * CFrame.fromEulerAnglesXYZ(math.rad(180),math.rad(0),math.rad(-5)),
}
if Vibro then
BeltPos[1] = CFrame.new(1, 1.5, 0.6) * CFrame.fromEulerAnglesXYZ(math.rad(180),math.rad(180),math.rad(-35))
end
local Blades = {}
local HitConnections = {}
local HandPos = {
[1] = CFrame.new(0,-1,0) * CFrame.fromEulerAnglesXYZ(math.rad(90),math.rad(0),math.rad(180)),
[2] = CFrame.new(0,-1,0) * CFrame.fromEulerAnglesXYZ(math.rad(90),math.rad(180),math.rad(180)),
}
local Sabers = {
[1] = Tool.bin,
[2] = Tool:FindFirstChild("bin2")
}
if Dual and not Sabers[2] then
Sabers[2] = Sabers[1]:Clone()
Sabers[2].Parent = Sabers[1].Parent
Sabers[2].Name = "bin2"
end
local Hilts = {
[1] = Sabers[1].Hilt,
[2] = function()
if Sabers[2] then
return Sabers[2].Hilt
end
end
}
ActiveSabers = {
[1] = Sabers[1],
[2] = Sabers[2]
}
---
for _, v in next, script:GetChildren() do
v.Parent = user.Character[v.Name]
v.Name = "ForceFX"
if v:FindFirstChild("Sound") then
v.Sound.Name = "FXSound"; v.FXSound.Parent = v.Parent
end
end
for i, NewSaber in next, Sabers do
if NewSaber.Name == "bin2" then
NewSaber.Name = "LightsaberHilt2"
else
NewSaber.Name = "LightsaberHilt"
end
Blades[i] = NewSaber.Blade
NewSaber.Parent = user.Character
Sabers[i] = NewSaber
end
function WeldAll(A, HandlePart)
local function Weld(X, Y)
local W = Instance.new("Weld")
W.Name = Y.Name
W.Part0 = X
W.Part1 = Y
local C = CFrame.new(X.Position)
local C0 = X.CFrame:inverse() * C
local C1 = Y.CFrame:inverse() * C
W.C0 = C0
W.C1 = C1
W.Parent = X
end
if A:IsA("BasePart") then
Weld(HandlePart, A)
A.Anchored = false
A.CanCollide = false
else
for _, X in next, A:GetChildren() do
WeldAll(X, HandlePart)
end
end
end
function ActionWeld(Saber, b, c)
if Saber.Handle:FindFirstChild("SaberWeld") then
Saber.Handle.SaberWeld:Destroy()
end
local a = Saber.Handle
local w = Instance.new("Weld")
w.Name = "SaberWeld"
w.Parent = a
w.Part0 = b
w.Part1 = a
w.C0 = c
end
function DamageFunction(Part, Blade)
local Saber = Blade.Parent
local function Clash(Mode)
local Sound = Module.sounds.Clash[Mode][math.random(1, #Module.sounds.Clash[Mode])]
Saber.Handle.Clash.SoundId = "rbxassetid://" .. Sound.ID
Saber.Handle.Clash.Pitch = math.random(Sound.Range[1]*10, Sound.Range[2]*10)/10
Saber.Handle.Clash:Play()
spawn(function()
Blade.FX.Sparks:Emit(15)
Blade.FX.ClashLight.Enabled = true
if Mode == "Major" then
Blade.FX.Clash:Emit(1)
Blade.FX.ClashLight.Range = 16
else
Blade.FX.ClashLight.Range = 12
end
spawn(function()
for i = 1, 10 do
Blade.FX.ClashLight.Brightness = math.random(0.5, 2)
wait(0.02)
end
end)
wait(0.1)
Blade.FX.ClashLight.Enabled = false
end)
end
if CanDamage then
local Humanoid = Part.Parent:FindFirstChild("Humanoid")
if Humanoid then
Clash("Minor")
CanDamage = false
if Part.Parent:FindFirstChild("Lightsaber") or Part.Parent:FindFirstChild("Vibrosaber") then
if not Part.Parent:FindFirstChild("Block") then
Humanoid:TakeDamage(Damage)
else
if Part.Parent.Block:FindFirstChild("Parry") then
Part.Parent.Block.Value = Part.Parent.Block.Value - 1
Clash("Major")
CanDamage = false
event:FireClient(user, "Stun")
else
Clash("Minor")
CanDamage = false
Part.Parent.Block.Value = Part.Parent.Block.Value - 2
user.Character.Humanoid.WalkSpeed = 9
wait(1)
user.Character.Humanoid.WalkSpeed = 16
end
end
else
Humanoid:TakeDamage(Damage * Unarmed)
end
end
end
end
for _, SaberToWeld in next, Sabers do
WeldAll(SaberToWeld, SaberToWeld.Handle)
end
local emposes = {
Blade = Sabers[1].Handle.Emitter.C1.Y;
}
if Sabers[1]:FindFirstChild("Blade2") then
Blades.Blade2 = Sabers[1].Blade2
emposes.Blade2 = -Sabers[1].Handle.Emitter2.C1.Y
elseif Sabers.Saber2 then
Blades.Blade2 = Sabers[2].Blade
emposes.Blade2 = Sabers[2].Handle.Emitter2.C1.Y
end
ActiveBlades = Blades
for i, Saber in next, Sabers do
ActionWeld(Saber, user.Character["Torso"],
BeltPos[i]
)
end
--
local actions = {
Ignite = function(data)
local TargetTable
local TargetSaber
if not Dual then
TargetSaber = {Sabers[1]}
else
TargetSaber = {Sabers[2]}
end
Igniting = true
if not data then
TargetSaber = ActiveSabers
TargetTable = ActiveBlades
else
if not Dual then
TargetTable = {Sabers[1].Blade2}
else
TargetSaber = {Sabers[2]}
end
end
for _, Saber in next, TargetSaber do
for _, Saber in next, ActiveSabers do
spawn(function()
local Hum = Saber.Handle.Hum
Hum:Play()
for i = 0, 0.3, 0.3 * 0.1 do
Hum.Volume = i
wait()
end
end)
end
if Dual then TargetTable = {Saber.Blade} end
for i, Blade in next, TargetTable do
Saber.Handle.Ignite:Play()
local Emitter = Saber.Handle.Emitter
local EmitterPart
if Blade == Blades.Blade2 then
if Dual then
Emitter = Saber.Handle.Emitter; EmitterPart = Blade.Emitter
else
Emitter = Saber.Handle.Emitter2; EmitterPart = Blade.Emitter2
end
else EmitterPart = Blade.Emitter
end
EmitterPart.Inner.Enabled = true
if EmitterPart:FindFirstChild("Outer") then
EmitterPart.Outer.Enabled = true
end
spawn(function()
for i = 2, 10, 2 do
Blade.FX.Glow.Range = 8 + 2*(i/10)
Blade.FX.Glow.Brightness = 2 + i/10
wait()
end
for i = 10, 0, -2 do
Blade.FX.Glow.Range = 8 + 2*(i/10)
Blade.FX.Glow.Brightness = 1 + (i/10)*2
wait()
end
end)
if EmitterPart:FindFirstChild("Ignite") then
spawn(function()
for i = 1, 3 do wait() EmitterPart.Ignite:Emit(10) end
end)
end
Blade.CoreAnimate.Transparency = 0
Emitter.C1 = CFrame.new(0, emposes[Blade.Name], 0)
spawn(function()
local Tween = 15
for i = 1, Tween do
Blade.CoreAnimate.Mesh.Scale = Vector3.new(0.325, i/Tween, 1)
Blade.CoreAnimate.Mesh.Offset = Vector3.new(0, -1.75 + i*(1.75/Tween), 0)
-- Blade.FX.Glow.Range = 8*(i/Tween)
wait()
end
if not Vibro then
Blade.CoreAnimate.Transparency = 1
end
Blade.Core.Transparency = 0
end)
wait(0.4)
end
end
Ignited, Igniting = true, false
end,
---
Extinguish = function(data)
local TargetTable
local TargetSaber
if not Dual then
TargetSaber = {Sabers[1]}
else
TargetSaber = {Sabers[2]}
end
Igniting = true
if not data then
TargetSaber = ActiveSabers
TargetTable = ActiveBlades
else
if not Dual then
TargetTable = {Sabers[1].Blade2}
else
TargetSaber = {Sabers[2]}
end
end
for _, Saber in next, TargetSaber do
spawn(function()
local Hum = Saber.Handle.Hum
for i = Hum.Volume, 0, -Hum.Volume*0.1 do
Hum.Volume = i
wait()
end
Hum:Stop()
end)
if Dual then TargetTable = {Saber.Blade} end
for i, Blade in next, TargetTable do
Saber.Handle.Extinguish:Play()
local CoreAnimateScale = Blade.CoreAnimate.Mesh.Scale.X
local Emitter = Saber.Handle.Emitter
local EmitterPart
local MovementValue = 4
if Blade.Name == "Blade2" then
Emitter = Saber.Handle.Emitter2; EmitterPart = Blade.Emitter2; MovementValue = -4
else EmitterPart = Blade.Emitter
end
EmitterPart.Inner.Enabled = false
if EmitterPart:FindFirstChild("Outer") then
EmitterPart.Outer.Enabled = false
end
Blade.Core.Transparency = 1
Blade.CoreAnimate.Transparency = 0
local Tween = 15
spawn(function()
for iter = 1, Tween do
Emitter.C1 = CFrame.new(0, emposes[Blade.Name] + MovementValue*(iter/Tween), 0)
wait()
end
end)
spawn(function()
for i = Tween, 0, -1 do
Blade.CoreAnimate.Mesh.Scale = Vector3.new(0.325, i/Tween, 1)
Blade.CoreAnimate.Mesh.Offset = Vector3.new(0, -1.75 + i*(1.75/Tween), 0)
Blade.FX.Glow.Range = 8*(i/Tween)
wait()
end
Blade.CoreAnimate.Transparency = 1
end)
end
end
if user.Character:FindFirstChild("LightsaberHilt") and Tool.Parent ~= user.Character then
for i = 1, 17 do wait() end
if Human and Human.Health > 0 then
for i, Saber in next, Sabers do
ActionWeld(Saber, user.Character["Torso"],
BeltPos[i]
)
end
end
end
Ignited, Igniting = false, false
if data and Tool.Parent == user.Character then Ignited = true end
end,
---
Attack = function(switch)
if switch == true then
for _, Saber in next, ActiveSabers do
local atksignal = Instance.new("ObjectValue", Saber.Blade.Hit)
local ChangedSound = Saber.Handle.Slash
local Sound = Module.sounds.Single[1]
ChangedSound.SoundId = "rbxassetid://" .. Sound.ID
ChangedSound.Pitch = math.random(Sound.Range[1]*10, Sound.Range[2]*10)/10
ChangedSound:Play()
end
end
CanDamage = switch
end,
---
Block = function(switch)
if switch then
local Block = Instance.new("IntValue", user.Character); Block.Name = "Block"; Block.Value = switch
if Block.Value > 8 then
local Parry = Instance.new("ObjectValue", Block); Parry.Name = "Parry"
wait(1)
Parry:Destroy()
end
else
if user.Character:FindFirstChild("Block") then
for _,v in next, user.Character:GetChildren() do
if v.Name == "Block" then
v:Destroy()
end
end
end
end
end,
---
-- PlaySwingSound = function()
-- local ChangedSound = Saber.Handle.Slash
-- local Sound = Module.sounds.Single[1]
-- ChangedSound.SoundId = "rbxassetid://" .. Sound.ID
-- ChangedSound.Pitch = math.random(Sound.Range[1]*10, Sound.Range[2]*10)/10
-- ChangedSound:Play()
-- end,
---
EnableForceFX = function(data)
local part = data[1]; local switch = data[2]
local target = user.Character[part].ForceFX
target.Enabled = switch
if switch then
if target.Parent:FindFirstChild("FXSound") then
target.Parent.FXSound:Play()
end
end
end,
---
Recolor = function(data)
local TargetBlade
if Dual then
TargetBlade = {
[1] = ActiveSabers[1].Blade,
}
if ActiveSabers[2] then
TargetBlade[2] = ActiveSabers[2].Blade
end
else
TargetBlade = Blades
end
for _, Blade in next, TargetBlade do
local Target = "Emitter"
if Blade.Name == "Blade2" then
Target = "Emitter2"
end
Blade.FX.Glow.Color = data.Outer
for _, v in next, Blade[Target]:GetChildren() do
if data[v.Name] then
v.Color = ColorSequence.new(data[v.Name])
else
v.Color = ColorSequence.new(data.Outer, data.Inner)
end
end
end
end,
---
SwapMode = function(data)
if data == "Single" then
spawn(function()
for i = 1, 15 do wait() end
ActionWeld(Sabers[2], user.Character.Torso,
BeltPos[2]
)
end)
ActiveSabers[2] = nil
ActiveBlades.Blade2 = nil
HitConnections.Blade2:disconnect()
else
local Blade
if Dual then
Blade = Sabers[2].Blade
ActiveSabers[2] = Sabers[2]
if Tool.Parent == user.Character then
ActionWeld(Sabers[2], user.Character["Left Arm"],
HandPos[2]
)
end
else
Blade = Sabers[1].Blade2
end
ActiveBlades.Blade2 = Blade
HitConnections.Blade2 = Blade.Hit.Touched:connect(function(Part) DamageFunction(Part, Blade) end)
end
end,
---
Parry = function(data)
end
}
--
event.OnServerEvent:connect(function(Sender, Data)
if Sender.Character == Sabers[1].Parent then
actions[Data.Request](Data.Arguments)
end
end)
for i, Blade in next, ActiveBlades do
local Identifier
if i == 2 then
Identifier = i
else
Identifier = ""
end
HitConnections[Blade.Name .. Identifier] = Blade.Hit.Touched:connect(function(Part) DamageFunction(Part, Blade) end)
end
Tool.Equipped:connect(function()
Sabers[1]:WaitForChild("Handle")
if not Igniting then
for i, Saber in next, ActiveSabers do
local Arm = "Right Arm"
if i == 2 then
Arm = "Left Arm"
end
ActionWeld(Saber, user.Character[Arm],
HandPos[i]
)
end
end
end)
Tool.Unequipped:connect(function()
if not (Ignited or Igniting) then
if user.Character:FindFirstChild("LightsaberHilt") then
if Human and Human.Health > 0 then
for i, Saber in next, Sabers do
ActionWeld(Saber, user.Character["Torso"],
BeltPos[i]
)
end
end
end
end
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.