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

Why does it only work on 1 wall[i]?

Alright so i'm basically making a move script and everything is working except now that I put multiple "walls" (wall = game.Workspace.walls:GetChildren), it will pass thru every single wall but 1. I want it to stop at all walls.

(This is a local script)

plr = game.Players.LocalPlayer
mouse = plr:GetMouse()
arrow = game.Workspace.point
move = nil

wall = game.Workspace.walls:GetChildren()




function CheckUp()
		local b = Instance.new("Part", game.Workspace)
	b.Name = "FINDER"
	b.Anchored = true
	b.CFrame = arrow.CFrame + Vector3.new(4,0,0)
	for i,v in pairs(wall) do
	if b.CFrame.X == wall[i].CFrame.X then
		move = false
		print("Wall infront")
	else 
		move = true
	end
	end--for end
end --function end

mouse.KeyDown:connect(function(key)
	if key == "w" then
		print("w")
		CheckUp()
		if move == false then
			arrow.CFrame = arrow.CFrame + Vector3.new(0,0,0)
		else
			arrow.CFrame = arrow.CFrame + Vector3.new(4,0,0)
		end


	end
end)

1 answer

On line 17, if you put "==" that means you want it to be that exact number for the two objects though it sometimes is different by 0.01 or 0.1 or something like that so maybe having a >= or a <= would help.

Also on like 30-34 why not just do if move == true then..... because your checking if its false and if it is your not doing anything your leaving it in its spot.

also I noticed your adding instead of multiplying the CFrame and Vector3 I highly recommend you multiply.

Here is the wiki post about CFrames, scroll to where it says Operators and read about it :) http://wiki.roblox.com/index.php?title=CFrame

-- Edit:

one other note is that if you have a lot of children for the "wall" then I recommend you add some sort of interval for the loop so you can add a wait() maybe like after x amount of checks it waits, because if you have too many children it will try to do it quickly and that can be really tough on some computers.

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