-
What do you want to achieve? I want to take 800 BugCoins from the leaderboard when i click the button.
-
What is the issue? robloxapp-20200729-2010290.wmv (2.3 MB)
-
What solutions have you tried so far? I tried to move the script.
Here is the Script
local cost = 800
local PetModule = require(game.ServerScriptService:WaitForChild("PetModule"))
script.Parent.ClickDetector.MouseClick:Connect(function(player)
if player.leaderstats.BugCoins.Value >= cost then
player.leaderstats.BugCoins.Value = player.leaderstats.BugCoins.Value - cost
local pet = PetModule.chooseRandomPet()
print(pet.Name.." selected")
end
end)
Here is the ModueScript/PetModule
local petModule = {}
petModule.pets = {
["Mythic"] = {
};
["Legendary"] = {
};
["Epic"] = {
};
["UnCommon"] = {
game.ReplicatedStorage.Pets.BlackCaterpillar;
game.ReplicatedStorage.Pets.WhiteCaterpillar;
};
["Common"] = {
game.ReplicatedStorage.Pets.GreenCaterpillar;
game.ReplicatedStorage.Pets.DarkGreenCaterpillar;
game.ReplicatedStorage.Pets.LightGreenCaterpillar;
};
}
petModule.rarities = {
["Mythic"] = 1;
["Legendary"] = 3;
["Epic"] = 17;
["UnCommon"] = 24;
["Common"] = 55;
}
petModule.chooseRandomPet = function()
local randomNumber = math.random(1,100)
local counter = 0
for rarity, weight in pairs(petModule.rarities) do
counter = counter + weight
if randomNumber <= counter then
local rarityTable = petModule.pet[rarity]
local chosePet = rarityTable[math.random(1,#rarityTable)]
return chosePet
end
end
end
return module