Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Script gives error when I plug in a variable into the function? [unanswered]

So this is my lightning script for my game and for some reason it stopped working at the zap function when I try to do bolt()

function bolt(pos)
			local CF = CFrame.new(workspace.Cloud.Position, pos) -- error
			local sound = script.StrikeSound:clone()
			sound.Volume = 1
			sound.Name = "Temp"..sound.Name
			sound.Parent = script
			game.Debris:AddItem(sound,10)
			for strike = 1, 8 do
			local lastPos = CF.p
				local Parts = 7
				local Arc = 20
				game.Lighting.Ambient = script.Flash.Value
				for i = 1, Parts do
					local targpoint = CF.p + ((CF.lookVector*((CF.p-pos).magnitude/Parts))*i) + Vector3.new(math.random(-Arc,Arc),math.random(-Arc,Arc),math.random(-Arc,Arc)) -- eror
					if i == Parts then
						targpoint = pos
					end
					local s = Instance.new("Part")
					s.formFactor = 0
					s.Size = Vector3.new(1,1,math.floor((lastPos-targpoint).magnitude))
					s.CFrame = CFrame.new((lastPos+targpoint)/2,targpoint)
					s.BrickColor = BrickColor.new("Bright yellow")
					s.Anchored = true
					s.CanCollide = false
					local m = Instance.new("BlockMesh")
					m.Scale = Vector3.new(5,5,1)
					m.Parent = s
					local sc = script.BoltScript:clone()
					print'incoming lightning'
					sc.Disabled = false
					sc.Parent = s
					s.Parent = workspace
					lastPos = targpoint
					
				end
				wait(0.07)
				game.Lighting.Ambient = script.Storm.Value
				wait(0.01)
			end
		end

2 comments

0

Where do you call zap()? Plus, you'll need to redefine playerlist every time you want to do something with it. 

0

Oh my bad I left out the portion of code when it was called but at this point it doesn't matter since Zap() isn't causing the issue its whats inside of the function of Zap that matters

1 answer

FindFirstChild expects a string, chosen is an object. Use chosen.Name instead of just chosen on line 53.

4 comments

0

Still didn't work :\

0

Looks like bolt expects a Vector3, in this case a position. You're feeding it an object (the result of game.Workspace:FindFirstChild(chosen)).

0

So I instead created this variable local tors = game.Players:FindFirstChild(chosen.Name).Character.Torso and it started giving me an error

0

I updated the script

This discussion is preserved as it was. New answers, comments, and votes are closed.