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

My selling script is not working? pls help. Error attempt to compare number with string

Why doesn't this work?

Error: Workspace.SellPlace.SellPart.Script:10: attempt to compare number with string

local Part = script.Parent
Part.Touched:Connect(function(HIT)
	local H = HIT.Parent:FindFirstChild("Humanoid")	
	if H then
		local player = game.Players:GetPlayerFromCharacter(HIT.Parent)	
if player then
	local leaderstats = player:WaitForChild("leaderstats")
	local Currency = leaderstats.Money 
	local Selling = leaderstats.Strength 
		if Selling.Value > 0 then
			Currency.Value = Currency.Value + Selling.Value *1 
			Selling.Value = 0
		end
end
end
end)

	

4 comments

0

Tell me, are those values held by a number value or a string value?

0

String value

0

Hello, there's no way to compare that "ABC" is greater than 0, unless you turn each letters to a specific numbers

0

Dont mind the "unless" part :>

1 answer

It seems like you made your strength value as a StringValue instead of IntValue. I also spotted a little mistake:

local Part = script.Parent
Part.Touched:Connect(function(HIT)
    local H = HIT.Parent:FindFirstChild("Humanoid") 
    if H then
        local player = game.Players:GetPlayerFromCharacter(HIT.Parent.Name)  -- You said HIT.Parent
if player then
    local leaderstats = player:WaitForChild("leaderstats")
    local Currency = leaderstats.Money 
    local Selling = leaderstats.Strength 
        if Selling.Value > 0 then
            Currency.Value = Currency.Value + Selling.Value *1 
            Selling.Value = 0
        end
end
end
end)

If this helped please thumbs up and accept this answer.

All the best,

PrismaticFruits

4 comments

0

HIT.Parent is correct. Function finds a player from character model, and not by name.

0

It didn't work but thx for helping

0

I got this error: Unable to cast value to Object

0

Then make sure your strength is an IntValue.

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