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

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

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?

1 comment

0

what is this

2 answers

✓ Accepted answer

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.

2 comments

0

thank you! this is very helpful.

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!

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

5 comments

0

okay i will try this thank you

0

I Changed it because I was wrong try the new one

0

oh alright

0

Did it work?

0

nope

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