Problems with Click Detector Gui

Hey, I’m currently trying to make a gui that appears on the click of a part. I have the gui ready in a ScreenGui, I have the part with a click detector. And that click detector has a script parented to it. But, when I click on the part, I get an error in the output saying:

[Workspace.Part.ClickDetector.Script:8: attempt to index function with ‘Clone’]

This is the code
local clickDetector = workspace.Part.ClickDetector
clickDetector.MaxActivationDistance = 10

local SCI = script.SCI

function SCI(player)
	if player.PlayerGui:FindFirstChild("SCI") == nil then
		local sciClone = SCI:Clone()
		sciClone.Parent = player.PlayerGui
	else
		
	end
end
 
clickDetector.MouseClick:Connect(SCI)
And this is the layout in the workspace

Workspace

Any help or something to point me in the right direction is appreciated.
Thanks.

You’re overriding the variable SCI with the function that you’ve declared. You’re replacing your variable from line 4 with the function in line 6.

Try:

local clickDetector = script.Parent
clickDetector.MaxActivationDistance = 10

local SCI = script.SCI

function SCIfunc(player)
    if player.PlayerGui:FindFirstChild("SCI") then
        -- do stuff if found
    else
        local sciClone = SCI:Clone()
        sciClone.Parent = player.PlayerGui
    end
end
 
clickDetector.MouseClick:Connect(SCIfunc)

I think that your problem is that you have a function named SCI and a variable named the same thing which would cause a problem. I hope this helps you :grinning:

Thanks for everyone’s help. I tried it out and it works now.

Reminder:
Yust set one og the replies that help to the solution.