#Listing Interactables

6 messages · Page 1 of 1 (latest)

sacred moth
#

Just need a little help with my script.
I'm making a script for interacting with objects, but I wanted it to be neat and in one script, so if something goes wrong I won't need to scurry around in a ton of scripts scattered around everywhere. I made the **alphabet **list as available codes to give to the different objects, and the **interactable **list for the objects that exist. Everything is alright, except when I click one of the parts (either one) it says - randomly - that I clicked it, or the other part was clicked.
(I'm new to scripting - a few months)

Script + locations:

#
local UIS = game:GetService("UserInputService")
UIS.MouseIconEnabled = false

local gui = script.Parent.Screen.idle



alphabet = {
    "a",
    "b",
    "c",
    "d",
    "e",
    "f",
    "g",
    "h",
    "i",
    "j",
    "k",
    "l",
    "m",
    "n",
    "o",
    "p"
}



interactables = {}

local num = 0
repeat
    num = num + 1
    table.insert(interactables, alphabet[num])
    
    print(num)
    wait()
until num == #(game.Workspace.interactables:GetChildren())

print(interactables)

local lock = false
local didclick = false

local function enter()
    gui.ImageTransparency = 1
end

local function leave()
    gui.ImageTransparency = 0
end

local function click()
    if lock == false then
        lock = true
        didclick = true
        lock = false
    end
end


while true do
    for i=1, #interactables do
        game.Workspace.interactables:FindFirstChild(interactables[i]).ClickDetector.MouseHoverEnter:Connect(enter)
        game.Workspace.interactables:FindFirstChild(interactables[i]).ClickDetector.MouseHoverLeave:Connect(leave)
        game.Workspace.interactables:FindFirstChild(interactables[i]).ClickDetector.MouseClick:Connect(click)
        wait()
        if didclick == true then
            didclick = false
            if i == 1 then
                print("part A")
            elseif i == 2 then
                print("part B")
            end
        end
        wait(1)
    end

    
    wait()
end
#

I messed around with detecting if the parts were clicked and the wait()'s so it's probably not the most efficient

#

There's no errors in the output

#

#1257448095868911656 message

sacred moth
#

Mr robot helped me 👋