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)
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)
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.
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)