Hi. I am trying to make a Pet Hatching system and I am running into a little problem. I am trying to get a value from leaderstats and it isn’t getting the value. I tried to look for solutions but I couldn’t really find anything. A snippet of my code is below.
if Player.leaderstats.Strength.Value >= tonumber(Price) then
Player.leaderstats.Strength.Value -= tonumber(Price)
script.Parent.ClickDetector.MouseClick:Connect(function(Player)
print(PlayersUsing[Player])
if PlayersUsing[Player]==true then print("Using") return end
PlayersUsing[Player] = true
print(tostring(Player))
print(tonumber(Player:WaitForChild("leaderstats").Strength.Value))
if Player.leaderstats.Strength.Value >= tonumber(Price) then
Player.leaderstats.Strength.Value -= tonumber(Price)
print("yes")
local TableOfPets = {}
for i, Pet in pairs(PetFolder:GetChildren()) do
local Rarity = Pet.Rarity.Value
for i = 1, PetRarities.Rarities[Rarity] do
table.insert(TableOfPets, Pet)
end
end
print("yes")
local PickedPet = TableOfPets[math.random(1, #TableOfPets)]
print(tostring(PickedPet))
local clone = PickedPet:Clone()
local HatchingGui = Player.PlayerGui.PetHatching
local Egg = HatchingGui:FindFirstChild("Frame"):FindFirstChild("Egg")
Egg.Visible=true
local Tick = tick()
local Timer = 3
while tick() - Tick<Timer do
Egg.Rotation = 8
wait(.05)
Egg.Rotation = 0
wait(.05)
Egg.Rotation = -8
wait(.05)
Egg.Rotation = 0
wait(.05)
end
Egg.Visible=false
local Pet = HatchingGui:FindFirstChild("Frame").PetImages:FindFirstChild(PickedPet.Name)
Pet.Visible = true
wait(3)
Pet.Visible=false
PlayersUsing[Player] = false
else
PlayersUsing[Player] = false
print(PlayersUsing[Player])
print("not enough money")
end
end)
If the code reading the strength value is a regular script then yes you do need to convert how you’re increasing the strength value to be on the server, though if you use anything UserInputService related, you’ll need to use RemoteEvents to tell the server to update the value