Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

"attempt to compare number with userdata" fix?

I'm trying to make a shop in my game (NO DataStores), where players can buy items using the in-game money (Galleons) they have - Which is earned by the amount of time they play the game.

However, when trying to purchase an item I keep receiving the same error and I can't find a way around it.

Please can someone help?


game.ReplicatedStorage.Potions.OnServerEvent:Connect(function(player,BuyButton)


if BuyButton == "Buy" then
  "I have been pressed" -- Checking the remote actually picks up, which it does!

  for  _, child in pairs(player.PlayerGui.ShopGui.Frame.PotionsList:GetChildren()) do
    if child.Name == "Death" and child.IWant.Value == true
    then 
      if player.leaderstats.Galleons >= 50 then
        A = game.ServerScriptService.Potions.DeathPotion
        B = A:clone()
        B.Parent = player.Backpack
        player.leaderstats.Galleons = player.leaderstats.Galleons - 50

      elseif child.Name == "Death" and child.IWant.Value == true then
        if player.leaderstats.Galleons <= 50 then
        end
        print("Not enough.")
      end
    end
  end
end
end)

Thanks.

1 comment

0

The error tells you what line. Userdata = Instance or Roblox data. deduce it yourself.

1 answer

✓ Accepted answer

Please, next time, post the error so people can see what line it is on.

if player.leaderstats.Galleons <= 50 then

player.leaderstats.Galleons is an Instance, which is a userdata. You should use player.leaderstats.Galleons.Value to access the value of a Value object.

This discussion is preserved as it was. New answers, comments, and votes are closed.