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

Trash Can Script Not Working?

Asked by 9 years ago

It is supposed to remove a empty cup from somones inventory and move it on top of a tray. Can you help me fix?

local mugs = script.Parent.Parent.Mugs
local M1,M2,M3,M4,M5,M6,M7,M8 = mugs.M1,mugs.M2,mugs.M3,mugs.M4,mugs.M5,mugs.M6,mugs.M7,mugs.M8
local enabled = true
local create = Instance.new

function RandPart(obj1)
    local parts = {}
    for _,v in pairs(obj1:GetChildren()) do
        table.insert(parts, v)
    end
    return parts[math.random(1,#parts)]
end

script.Parent.ClickDetector.MouseClick:connect(function(player)
    if player:GetRankInGroup(1107003) == 0 then
        if script.Parent.Parent.Mugs.M8.Transparency == 0 then
            MugsInvis()
            y = player.Backpack
            z = game.Lighting.Tray
            z:Clone().Parent = y
            player.Character.Humanoid:EquipTool(z)  
        end
    end
end)

script.Parent.Touched:connect(function(h)
    if h.Parent ~= nil and h.Parent.Name == "Mug" and h.Parent.Trash.Value == true then
        if enabled then
            enabled = false
            if M1.Transparency == 1 then
                M1.Transparency = 0
                enabled = true
                h.Parent:Destroy()
            elseif M2.Transparency == 1 then
                M2.Transparency = 0
                enabled = true
                h.Parent:Destroy()
            elseif M3.Transparency == 1 then
                M3.Transparency = 0
                enabled = true
                h.Parent:Destroy()
            elseif M4.Transparency == 1 then
                M4.Transparency = 0
                enabled = true
                h.Parent:Destroy()
            elseif M5.Transparency == 1 then
                M5.Transparency = 0
                enabled = true
                h.Parent:Destroy()
            elseif M6.Transparency == 1 then
                M6.Transparency = 0
                enabled = true
                h.Parent:Destroy()
            elseif M7.Transparency == 1 then
                M7.Transparency = 0
                enabled = true
                h.Parent:Destroy()
            elseif M8.Transparency == 1 then
                M8.Transparency = 0
                enabled = true
                h.Parent:Destroy()
            else
                local h = create("Hint", Workspace)
                h.Text = "Employee needed to wash mugs"
                wait(4)
                h:Destroy()
                enabled = true
            end
        end
    end
end)

function MugsInvis()
    for _,v in pairs(script.Parent.Parent.Mugs:GetChildren()) do
        if v:IsA("BasePart") then
            v.Transparency = 0
        end
    end
end

1 answer

Log in to vote
0
Answered by
Uroxus 350 Moderation Voter
9 years ago

I don't know if it's my computer not loading properly or if you havnt put your code within the LUA block... If you havnt, in future click the blue circle with "LUA" inside and put your code in that, makes it easier to read... Until you've done that, in not even going to begin to read it...

Ad

Answer this question