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

Why is this script i wrote to make me walk through walls giving me an error?

Asked by 4 years ago
Edited 4 years ago

i wrote the following localscript that goes in startercharacterscripts which is supposed to allow me to walk through walls

wait(2)
if script.Parent.Name == "defaultkid99" then
    while true do
        wait(4)
        local parts workspace:GetChildren()
        if parts.Name == workspace.Wall.Name then
            parts.CanCollide = false
            parts.Transparency = 0.4
        else
            parts.Transparency = 0.4
            parts.CanCollide = true
        end
        wait(8)
        parts.CanCollide = true
        parts.Transparency = 0
    end
end

however it gives me an error that says attempted to index nil with Name. what can i do to fix this?

0
what is this defaultkid99 4 — 4y

2 answers

Log in to vote
0
Answered by
ben0h555 417 Moderation Voter
4 years ago

Simple, when you use the GetChildren method, it returns a table, not an instance itself. So you need to loop through the table instead, try this:

wait(2)
if script.Parent.Name == "defaultkid99" then
    while true do
        wait(4)
        local parts = workspace:GetChildren()
        for i,v in next, parts do
                if v.Name == workspace.Wall.Name then
                    v.CanCollide = false
                    v.Transparency = 0.4
            end
        end
        wait(8)
        for i,v in next, parts do
            if v.Name == workspace.Wall.Name then
                v.CanCollide = true
                v.Transparency = 0
            end
        end
    end
end

As you can see it uses a loop to go through the table, v is one of the children and I do a quick 'if check' and then if that passes I run the code on it. This prevents the error, and brings it functionality.

0
thank you! this is very helpful. defaultkid99 4 — 4y
0
oh wow. this script was even more helpful than i thought it would be. now i figured out how to make a time stop script out of this one. thanks again! defaultkid99 4 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Try this

while wait(6) do
        local parts =  workspace:GetChildren()
            parts.Touched:Connect(function(hit)
            if parts.Name == workspace.Wall  then
                    if hit.Parent.Name == "defaultkid99" then
                        parts.CanCollide = false
                         parts.Transparency = 0.4
                    end
                    wait(8)
                    parts.CanCollide = true
                    parts.Transparency = 0
        end
    end)
end
0
okay i will try this thank you defaultkid99 4 — 4y
0
I Changed it because I was wrong try the new one gamingwithjbthepro 76 — 4y
0
oh alright defaultkid99 4 — 4y
0
Did it work? gamingwithjbthepro 76 — 4y
0
nope defaultkid99 4 — 4y

Answer this question