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

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

Asked by 4 years ago
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

0
These aren't needed (workspace:GetDescendants()). Just do workspace:GetDecendants() KingDomas 153 — 4y
0
are you sure KingDomas? asdfghjk9019 225 — 4y

1 answer

Log in to vote
2
Answered by
quinzt 201 Moderation Voter
4 years ago

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
0
THANK YOU SO MUCH AJAJAJAJAJAJAJAJA seanieplays 88 — 4y
Ad

Answer this question