Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

invalid argument #2(Vector3 expected, got nil). How do I fix this? Error at line 31

Asked by 3 years ago
Edited 3 years ago

So, I tried to make a lightning superpower script, and somehow, I got it wrong:


wait(1) ---- Services ---- local ReplicatedStorage = game:GetService("ReplicatedStorage") ---- Variables ---- local Remote = ReplicatedStorage:WaitForChild("ZapEvent") local bolt = Instance.new("Part") bolt.Size = Vector3.new(.3,.3,.3) bolt.BrickColor = BrickColor.new("Electric blue") bolt.CanCollide = false bolt.Anchored = true bolt.Material = "Neon" local function shootElectrode(from,too) local lastPos = from local step = 2 local off = 2 local range = 100 local distance = (from-too).magnitude <-- Error here-- if distance > range then distance = range end for i = 0,distance, step do local from = lastPos local offset = Vector3.new( math.random(-off,off), math.random(-off,off), math.random(-off,off) )/10 local too = from +- (from-too).unit * step + offset local p = bolt:Clone() local DebrisFolder = workspace:FindFirstChild("DebrisFolder") or Instance.new("Folder",workspace) DebrisFolder.Name = "DebrisFolder" p.Parent = DebrisFolder p.Size = Vector3.new(p.Size.x,p.Size.y,(from-too).magnitude) p.CFrame = CFrame.new(from:Lerp(too,0.5),too) game.Debris:AddItem(p,0.1) lastPos = too end end local function continueScale(Part) local TweenService = game:GetService("TweenService") local TweenInform = TweenInfo.new( .2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0 ) local Properties = { Size = Vector3.new(2.901,2.772,35) } local Tween = TweenService:Create(Part,TweenInform,Properties) Tween:Play() end Remote.OnServerEvent:Connect(function(Player,Aim,MousePos) local Character = Player.Character local RootPart = Character:WaitForChild("HumanoidRootPart") local RightHand = Character:WaitForChild("RightHand") local Humanoid = Character:WaitForChild("Humanoid") if Aim then local DebrisFolder = workspace:FindFirstChild("DebrisFolder") or Instance.new("Folder",workspace) DebrisFolder.Name = "DebrisFolder" local Animation = Instance.new("Animation") Animation.AnimationId = "rbxassetid://6425400204" local LoadAnimation = Character.Humanoid:LoadAnimation(Animation) LoadAnimation:Play() local BodPos = Instance.new("BodyPosition") BodPos.MaxForce = Vector3.new(5000000,5000000,5000000) BodPos.P = 50000 BodPos.Position = RootPart.Position BodPos.Parent = RootPart spawn(function() wait(3) BodPos:Destroy() end) local YCFrame = RootPart.Position.Y - Humanoid.HipHeight local CharParts = Character:GetChildren() math.randomseed(tick()) spawn(function() for i = 1,#CharParts do local Current = CharParts[i] if Current.ClassName == "Part" or Current.ClassName == "MashPart" then shootElectrode(Vector3.new(RootPart.Position.X - math.random(-5,5), YCFrame, RootPart.Position.Z - math.random(-5,5), Current.Position)) shootElectrode(Vector3.new(RootPart.Position.X - math.random(-5,5), YCFrame, RootPart.Position.Z - math.random(-5,5), Current.Position)) wait() end end end) else local DebrisFolder = workspace:FindFirstChild("DebrisFolder") or Instance.new("Folder",workspace) DebrisFolder.Name = "DebrisFolder" local HitBox = Instance.new("Part") HitBox.Anchored = false HitBox.Transparency = 1 HitBox.CanCollide = false HitBox.BrickColor = BrickColor.new("Really black") HitBox.Size = Vector3.new(5,5,5) HitBox.Parent = DebrisFolder spawn(function() local repeatnum = 22 for i = 1,repeatnum do shootElectrode(RightHand.Position,MousePos.Position) shootElectrode(RightHand.Position,MousePos.Position) wait() end HitBox:Destroy() end) local Mag = (RightHand.Position - MousePos.Position).magnitude if Mag > 100 then Mag = 100 end HitBox.Size = Vector3.new(5,5,Mag) HitBox.Position = RightHand.Position HitBox.CFrame = CFrame.new(RightHand.Position,MousePos.Position) HitBox.CFrame = HitBox.CFrame * CFrame.new(0,0,-Mag/2) spawn(function() local Sound = Instance.new("Sound") Sound.SoundId = "rbxassetid://34419186924" Sound.Parent = RootPart Sound.PlaybackSpeed = .8 Sound.RollOffMaxDistance = 300 Sound.Volume = 7 Sound:Play() wait(5) Sound:Destroy() end) local Hitppl = {} local beenHit wait(.05) HitBox.Touched:Connect(function(hit) if not hit.Parent:FindFirstChild("Humanoid") then return end if hit.Parent.Name ~= Character.Name then local NewCharacter = hit.Parent if Hitppl[Player.Name] then return end Hitppl[Character.Name] = true local Animation = Instance.new("Animation") Animation.AnimationId = "rbxassetid://6429800435" local LoadAnimation = NewCharacter:FindFirstChild("Humanoid"):LoadAnimation(Animation) LoadAnimation:Play() local BodPos = Instance.new("BodyPosition") BodPos.MaxForce = Vector3.new(5000000,5000000,5000000) BodPos.P = 50000 BodPos.Position = NewCharacter:FindFirstChild("HumanoidRootPart").Position BodPos.Parent = NewCharacter:FindFirstChild("HumanoidRootPart") NewCharacter:FindFirstChild("Humanoid"):TakeDamage(30) wait(.1) if hit.Parent:FindFirstChild("Humanoid").Health <= 0 then game.Debris:AddItem(BodPos,.1) else game.Debris:AddItem(BodPos,2) end end end) end end)

put ur code into a block, blue Lua icon in the editor

0
Theres like a hundred line of codes, post the whole error message Azure_Kite 885 — 3y
0
Ok REEL1212 0 — 3y
0
Also, the only error at line 31 if you are asking REEL1212 0 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Problem lies on line 117 and 118

 shootElectrode(Vector3.new(RootPart.Position.X - math.random(-5,5), YCFrame, RootPart.Position.Z - math.random(-5,5), Current.Position))

 shootElectrode(Vector3.new(RootPart.Position.X - math.random(-5,5), YCFrame, RootPart.Position.Z - math.random(-5,5), Current.Position))

You only give it a single argument

while shootElectrode requires 2 arguments which is from and too

shootElectrode(from, too)

too is nil because you only gives value to argument 1

So it errors when you try to do

local distance = (from-too).magnitude

because too is nil

What you probably meant to type in line 117 and 118 is

 shootElectrode(Vector3.new(RootPart.Position.X - math.random(-5,5), YCFrame, RootPart.Position.Z - math.random(-5,5)), Current.Position)

 shootElectrode(Vector3.new(RootPart.Position.X - math.random(-5,5), YCFrame, RootPart.Position.Z - math.random(-5,5)), Current.Position)

because on the previous one, "Current.Position" was inside the Vector3.new

Ad

Answer this question