Mouse click on a part issues

Hi! I would like to click on the ‘Part_1’ and show the screengui, how can I do it?

The truth is I am a bit confused with this, could someone give me a hand? I would appreciate it very much.

StarterPlayer Script:

local parts_touchs = {
	['RedTeam'] = {
		['Part_1'] = game.Workspace.Part1,
		['Part_2'] = game.Workspace.Part2
		-- I want to add others mores parts..
	}
}

Depends how you want to approach it.

You have 2 options:
1- clickdetector
2- playermouse

local userInputService = game:GetService('UserInputService')
local players = game:GetService('Players')

local parts = {
    [workspace.Part1] = screengui1; -- associate each part with a screengui
    [workspace.Part2] = screengui2;
}
local hoverPart = nil -- part to be assigned if in the parts table
local mouse = players.LocalPlayer:GetMouse() -- get the mouse object
mouse.Move:Connect(function()
    if mouse.Target then
        if parts[mouse.Target] then -- if a screengui is associate with the target
            hoverPart = mouse.Target
        else
            hoverPart = nil -- otherwise, assign the hoverpart variable to nil
        end
    end
end)
userInputService.InputBegan:Connect(function(input, isSystemReserved)
    if (hoverPart) and (not isSystemReserved) and input.InputType == Enum.InputType.MouseButton1 then
        print('Showing',parts[hoverPart])
        parts[hoverPart].Enabled = true
    end
end)

and with click detector how could I do it?
I only want that when i click the part with the mouse the screengui go enable

You’d just use clickdetector.MouseClick

2 Likes

Thanks! it worked for me, thanks for your help :smiley:

1 Like