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

Why is the i,v loop not detecting the "Tape" objects?

local function touched(v)
	print("a")
	v.Touched:Connect(function(t)
		print(t.Name)
		if(t.Name == "OpenBox")then
			local box = game.ReplicatedStorage.Items.Box:Clone()
			box.CFrame = t.CFrame
			t:Destroy()
			box.Parent = workspace
		end
	end)
end

local function spawnitems(spawner)
	while wait(10) do
		local folder = {game.ReplicatedStorage.Items.OpenBox, game.ReplicatedStorage.Items.Envelope}
		local part = folder[math.random(1,#folder)]:Clone()
		part.Parent = workspace
		part.CFrame = spawner.CFrame
		part.Velocity = Vector3.new(0,0,-20)
	end
end

for i,v in pairs(workspace:GetDescendants())do
	if(v.Name == "Conveyor")then
		v.Velocity = v.CFrame.LookVector * 20
	end
	
	if(v.Name == "Tape")then
		print("KJASDKJSADKJasjkd")
		touched(v)
	end
	
	if(v.Name == "Spawner")then
		spawnitems(v)
	end
end

it can detect everything else but not tapem even if the string exactly matches with the name

2 comments

0

These aren't needed (workspace:GetDescendants()). Just do workspace:GetDecendants()

0

are you sure KingDomas?

1 answer

✓ Accepted answer

simple mistake, use elseif instead of just if. so,

for i,v in pairs(workspace:GetDescendants())do
    if(v.Name == "Conveyor")then
        v.Velocity = v.CFrame.LookVector * 20

    elseif(v.Name == "Tape")then
        print("KJASDKJSADKJasjkd")

    elseif(v.Name == "Spawner")then
        print("bruh")
    end
end

1 comment

0

THANK YOU SO MUCH AJAJAJAJAJAJAJAJA

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