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

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

Asked by
Prioxis 673 Moderation Voter
8 years ago

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

0
Where do you call zap()? Plus, you'll need to redefine playerlist every time you want to do something with it.  GoldenPhysics 474 — 8y
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 Prioxis 673 — 8y

1 answer

Log in to vote
0
Answered by
Lamar 45
8 years ago

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

0
Still didn't work :\ Prioxis 673 — 8y
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)). Lamar 45 — 8y
0
So I instead created this variable local tors = game.Players:FindFirstChild(chosen.Name).Character.Torso and it started giving me an error Prioxis 673 — 8y
0
I updated the script Prioxis 673 — 8y
Ad

Answer this question