How Do I Use A Click Detector In A Billboard Gui

I’m not sure if I’m doing this right. Whenever I click on the BillboardGui nothing happens. Am I supposed to put ClickDetector and the Script in imageLabel?

local cost = 1

local cardModule = require(game.ServerScriptService:WaitForChild("WoodenChestModule"))

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	
	if player.leaderstats("Dark Elixir"). Value >= cost then
		
		player.leaderstats("Dark Elixir").Value = player.leaderstats("Dark Elixir").Value - cost
		
		local card = cardModule.chooseRandomcard()
		
		print(card.Name.." selected")
		
	end
	
end)
3 Likes

No. You are supposed to put the click detector in the part.

2 Likes

Yep, as @sjr04 said, the clickdetector needs to be inside of the part. Change it to this:


local detector = script.Parent.ClickDetector
local cost = 1

local cardModule = require(game.ServerScriptService:WaitForChild("WoodenChestModule"))


detector.MouseClick:Connect(function(player)
    local darkelixir = player:WaitForChild("leaderstats"):WaitForChild("Dark Elixir")
	if darkelixir.Value >= cost then
		darkelixir.Value = darkelixir.Value - cost
		
		local card = cardModule.chooseRandomcard()
		print(card.Name.." selected")
	end
end) 
1 Like

Sorry I’m confused, so if I put the click detector in the part will the player have to click the part or can they click the billboard gui?

1 Like

If you want the player to click on the billboard gui, use a button. If you want them to click on the part use a click detector.

1 Like

Just use a TextButton instead.

1 Like

But I want them to click on the image label. Do I put a blank text button on top of the image label?

Yeah, you do. Or you change the imagelabel to a imagebutton.

2 Likes

Is it supposed to go like this, because nothing happens still

Can you show me the code you used?

local cost = 1

local cardModule = require(game.ServerScriptService:WaitForChild("WoodenChestModule"))

script.Parent.MouseButton1Click:Connect(function(player)
	
	if player.leaderstats("Dark Elixir"). Value >= cost then
		
		player.leaderstats("Dark Elixir").Value = player.leaderstats("Dark Elixir").Value - cost
		
		local card = cardModule.chooseRandomcard()
		
		print(card.Name.." selected")
		
	end
	
end)

Oh! It’s because you can only use the code on the client, and you’d have to put that code in startergui and change script.parent to the path of the button. You could use RemoteEvents to handle the server code.

What is inside the script? Maybe that’s the problem.

Should this be a local script instead of a script?

I did this in a script and it worked, but the setup is different. It’s in a part instead. Does that make a difference?

Also this was my code

local cost = 500

local petModule = require(game.ServerScriptService:WaitForChild("PetModule"))

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	
	if player.leaderstats.Cash.Value >= 500 then
		
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - cost
		
		local pet = petModule.chooseRandomPet()
		
		print(pet.name.." selected")
		
		game.ReplicatedStorage.HatchEgg:FireClient(player, pet)
		
	end
	
end)
1 Like

A billboard can’t use click detectors, only buttons etc.

Yeah but what about the script? I’d have to do what @TheWorstOne_2 said, if I wanted it to be in a billboard gui?