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?
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.
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