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

How to fix 'Attempt to index nil with Play'?

Asked by 1 year ago
Edited 1 year ago

I'm having this error when I try to use TweenService. The error is on line 132. This is the code.

tweenmodule = require(game.ReplicatedStorage.TMmoduleV2)
db = false
pinsdown = {}
Tweens = {}
local ts = game:GetService("TweenService")
eg = {}
eg.Position = Vector3.new(41.413, 10.676, 164.464)
eg.Orientation = Vector3.new(0,90,0)
local eg1 = {}
eg1.Position = Vector3.new(43.331, 10.676, 157.219)
eg1.Orientation = Vector3.new(0,90,0)
local eg2 = {}
eg2.Position = Vector3.new(45.215, 10.676, 164.464)
eg2.Orientation = Vector3.new(0,90,0)
local eg3 = {}
eg3.Position = Vector3.new(45.219, 10.676, 159.899)
eg3.Orientation = Vector3.new(0,90,0)
local eg4 = {}
eg4.Position = Vector3.new(46.937, 10.676, 162.233)
eg4.Orientation = Vector3.new(0,90,0)
local eg5 = {}
eg5.Position = Vector3.new(41.303, 10.676, 159.899)
eg5.Orientation = Vector3.new(0,90,0)
local eg6 = {}
eg6.Position = Vector3.new(37.991, 10.676, 164.464)
eg6.Orientation = Vector3.new(0,90,0)
local eg7 = {}
eg7.Position = Vector3.new(48.437, 10.676, 164.464)
eg7.Orientation = Vector3.new(0,90,0)
local eg8 = {}
eg8.Position = Vector3.new(43.326, 10.676, 162.233)
eg8.Orientation = Vector3.new(0,90,0)
local eg9 = {}
eg9.Position = Vector3.new(39.646, 10.676, 162.233)
eg9.Orientation = Vector3.new(0,90,0)
Tweeninfo = TweenInfo.new(1.5, Enum.EasingStyle.Linear)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------
wait(1)
t1 = tweenmodule.TweenModulePosition(script.Parent.Model,TweenInfo.new(1.5,Enum.EasingStyle.Linear),Vector3.new(43.178, 5.643, 161.958))
wait(1.5)
d = script.Parent.Model:GetChildren()
for i,v in pairs(d) do
    v.Anchored = false
end
function cycle1()
            wait(3)
            for i,v in pairs(d) do
                v.Anchored = true
                v.CanCollide = true
            end
            wait(1)
            local t1 = ts:Create(script.Parent.Model.Pin1, Tweeninfo, eg)
            local t2 = ts:Create(script.Parent.Model.Pin2, Tweeninfo, eg1)
            local t3 = ts:Create(script.Parent.Model.Pin3, Tweeninfo, eg2)
            local t4 = ts:Create(script.Parent.Model.Pin4, Tweeninfo, eg3)
            local t5 = ts:Create(script.Parent.Model.Pin5, Tweeninfo, eg4)
            local t6 = ts:Create(script.Parent.Model.Pin6, Tweeninfo, eg5)
            local t7 = ts:Create(script.Parent.Model.Pin7, Tweeninfo, eg6)
            local t8 = ts:Create(script.Parent.Model.Pin8, Tweeninfo, eg7)
            local t9 = ts:Create(script.Parent.Model.Pin9, Tweeninfo, eg8)
            local t10 = ts:Create(script.Parent.Model.Pin10, Tweeninfo, eg9)
            t1:Play()
            t2:Play()
            t3:Play()
            t4:Play()
            t5:Play()
            t6:Play()
            t7:Play()
            t8:Play()
            t9:Play()
    t10:Play()
end

--5.643
local function IsPinDown(pinNumber)
    local pin = script.Parent.Model:FindFirstChild("Pin"..pinNumber)
    local rotX,rotZ, rotY = pin.Orientation.X, pin.Orientation.Z, pin.Orientation.Y
    if rotX ~= 5 or rotZ ~= 5 or rotY ~= 5 then
        table.insert(pinsdown, "t"..pinNumber)
        return "IsDown"
    else
        return "NotDown"
    end
end
function preputdowncycle2()
    pinsdown = {}
    for i = 1, 10 do
        IsPinDown(i)
    end
    eg.Position = Vector3.new(41.413, 6.142, 164.464)
    eg.Orientation = Vector3.new(0,90,0)
    eg1 = {}
    eg1.Position = Vector3.new(43.331, 6.142, 157.219)
    eg1.Orientation = Vector3.new(0,90,0)
    eg2 = {}
    eg2.Position = Vector3.new(45.215, 6.142, 164.464)
    eg2.Orientation = Vector3.new(0,90,0)
    eg3 = {}
    eg3.Position = Vector3.new(45.219, 6.142, 159.899)
    eg3.Orientation = Vector3.new(0,90,0)
    eg4 = {}
    eg4.Position = Vector3.new(46.937, 6.142, 162.233)
    eg4.Orientation = Vector3.new(0,90,0)
    eg5 = {}
    eg5.Position = Vector3.new(41.303, 6.142, 159.899)
    eg5.Orientation = Vector3.new(0,90,0)
    eg6 = {}
    eg6.Position = Vector3.new(37.991, 6.142, 164.464)
    eg6.Orientation = Vector3.new(0,90,0)
    eg7 = {}
    eg7.Position = Vector3.new(48.437, 6.142, 164.464)
    eg7.Orientation = Vector3.new(0,90,0)
    eg8 = {}
    eg8.Position = Vector3.new(43.326, 6.142, 162.233)
    eg8.Orientation = Vector3.new(0,90,0)
    eg9 = {}
    eg9.Position = Vector3.new(39.646, 6.142, 162.233)
    eg9.Orientation = Vector3.new(0,90,0)
    local t1 = ts:Create(script.Parent.Model.Pin1, Tweeninfo, eg)
    local t2 = ts:Create(script.Parent.Model.Pin2, Tweeninfo, eg1)
    local t3 = ts:Create(script.Parent.Model.Pin3, Tweeninfo, eg2)
    local t4 = ts:Create(script.Parent.Model.Pin4, Tweeninfo, eg3)
    local t5 = ts:Create(script.Parent.Model.Pin5, Tweeninfo, eg4)
    local t6 = ts:Create(script.Parent.Model.Pin6, Tweeninfo, eg5)
    local t7 = ts:Create(script.Parent.Model.Pin7, Tweeninfo, eg6)
    local t8 = ts:Create(script.Parent.Model.Pin8, Tweeninfo, eg7)
    local t9 = ts:Create(script.Parent.Model.Pin9, Tweeninfo, eg8)
    local t10 = ts:Create(script.Parent.Model.Pin10, Tweeninfo, eg9)
    for i, v in pairs(pinsdown) do
        local currentitem = v[1]
        currentitem:Play() --this is the line that I'm getting the error from.
    end
    wait(3)
    for i,v in pairs(d) do
        v.Anchored = false
        v.CanCollide = true
        end
end
game.Workspace.TouchPart.Touched:Connect(function(hit)
    if hit.Name == "Rekt" and db == false then
        db = true
        cycle1()
        wait(3)
        preputdowncycle2()
        db = false
    end
end)

2 answers

Log in to vote
0
Answered by
manith513 121
1 year ago

Looks like your table pinsdown is empty and isn't adding anything in your code unless I'm missing something? so add your tween to item 1 of your pinsdown table thats why its a nil as of now.

Ad
Log in to vote
0
Answered by
pwx 1581 Moderation Voter
1 year ago

You have set the variable for 'pinsdown' twice, resetting it. Remove it from line 087.

Answer this question