When I Click The Button, It Doesn't Print

Hello! (This is my first time time posting on the DevForum, so go easy on me please.)
So, I’m fairly new to scripting, but know some of the basics. So, I’m making a script where if you click on it, it takes you to the creature you chose. But, the ClickDetector isn’t working. I originally had the script outside the ClickDetector, but I put it in the ClickDetector and nothing has changed. It prints hello but when I click on a button, it does not work. I don’t know if anyone has done this topic exactly like I have. I looked up many other topics, but none matched. Maybe it’s because it’s in PlayerGui?

Here’s the code:

--LOCALS--
local Player = game.Players.LocalPlayer
local VP = script.Parent.Parent
local Base = game.Workspace.Base
local Cam = game.Workspace.CurrentCamera
local ClickDetect = script.Parent

-- TEST--
Print("Hello")
--SETUP--
ClickDetect.MouseClick:connect(function(OnClick) --Button1
	print("ClickStarted")
end)

And here is where it’s located:


It’s located in every ClickDetector, the ClickDetector is in the button, the Button is in the ViewportFrame. This goes for every ViewportFrame.

Local Scripts cant call the MouseClick event, I assume. Use a Server Script instead of a LocalScript, see if that would change anything.

1 Like

Clickdetectors don’t work with Gui Buttons they have their own event for mousclick.

You don’t need to have ClickDetectors in Buttons. Instead, parent the localscript to the button and use the MouseButton1Click event that roblox provides!

local button = script.Parent

button.MouseButton1Click:Connect(function()
    print("Button clicked!")
end)
2 Likes

@jaipack17 and @BabyNinjaTime , you both helped me! Is there a way to mark both of your comments as solutions?

1 Like

Glad we could help, you can mark BabyNinja’s reply as the solution! :+1:

1 Like

Oh, ok! Thank you both, I’ll mark BabyNinja’s reply as the solution.

1 Like