Confused on script

can anyone please help me fix this problem?:
image
script:
image

Are you sure price and value of Gems is a number?

1 Like

what do you mean by that??? :face_with_raised_eyebrow:

I assume you’re making a shop system. In which case checking if the player can afford that item.

The error is saying that the value of the price variable is a string when the other value (gems) is a number. They both need to be the same type.

Can you also send your full script so I can get a closer look?

1 Like

nope im making a egg system, but ok

How are you setting price?
Is Gems.Value an IntValue or a NumberValue or a StringValue.

1 Like

int value i set it that on my second script

Try turning the price variable into a number and test it again.

did that already did the same response

Try it on your gems value then.

also ive got two scripts for it well 3, but one is a model script

Send the script that is erroring.

1 Like

I didn’t ask where, I asked how.
Does the player enter a text message value?
Is it set as a number by the script?

Try print(leaderstats.Gems.Value, " price = ", price)

1 Like

ok here:

local replicatedStorage = game:GetService("ReplicatedStorage")
local player = game:GetService("Players")

local remotes = replicatedStorage.Remotes
local eggs = workspace.Mainfolder_workspace.Eggs

local playerHatchDebounce = {}

local function chooseRandomPet(petTable)
	local chosenPet = nil
	local randomNumber = math.random(1, 100)
	local weight = 0

	for i, v in pairs(petTable) do
		weight += v.chance

		if weight >= randomNumber then
			chosenPet = v
			break
		end
	end

	return chosenPet
end

for _, egg in pairs(eggs:GetChildren()) do
	egg.ProximityPrompt.Triggered:Connect(function(Player)
		local eggData = require(egg.Data)
		local price = eggData.eggPrice
		local currency = eggData.eggCurrency

		if Player.leaderstats.Gems.Value >= price then
			if not playerHatchDebounce[player] then
				playerHatchDebounce[player] = true
				local chosenPet = chooseRandomPet(eggData.eggPets)
				Player.leaderstats[currency].Value -= price
				remotes.HatchEgg:FireClient(player, egg.Name, chosenPet)
				local leaderFolder = Player:WaitForChild("leaderstats")
				leaderFolder.Name = tostring(chosenPet.petName)
				leaderFolder.Parent = player.Pets
				task.wait(6)
				playerHatchDebounce[player] = false
			end
		end
	end)
end

player.PlayerRemoving:Connect(function(player)
	if playerHatchDebounce[player] then
		playerHatchDebounce[player] = nil
	end
end)

So, is eggPrice actually a number?

1 Like

do you mean like seriously or in the script?

Also try this: print(typeof(price), typeof(Player.leaderstats.Gems.Value)) to find out which one is causing the error.

1 Like

what in a different script or the same one?

In the same script.

limitlimit

1 Like

The issue is how you set eggprice.
If it’s a value in a table that has been entered as a StringValue instead of a NumberValue then of course it’ll error.
That’s why we are asking these questions, to help you understand the issue.
The print line I told you to try needs to be put in front of your error line.

1 Like