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

attempt to compare number with string (?)

-- someone please explain why it puts attempt to compare number with string in the output of this -- script.

game.Players.LocalPlayer:WaitForChild("leaderstats") -- because it waits a while before it loads

repeat wait()
Player = game.Players.LocalPlayer
Button = script.Parent
Item = game.ReplicatedStorage:FindFirstChild("BombosSurvivalKnife")
Cost = 1000
Money = Player.leaderstats.Robux
until

Button.MouseButton1Down:connect(function(purchase)
	if Money.Value > (Cost - 1) then
		Money.Value = Money.Value - Cost
		local a = Item:Clone()
		a.Parent = Player.Backpack
		local b = Item.Clone()
		b.Parent = Player.StarterGear
	end
end) 

2 comments

0

Is Money a stringvalue? You could try if tonumber(Money.Value) > (Cost - 1) then

0

edited to fix code block

1 answer

You are using repeat wait() until incorrectly. Remove it, and use :WaitForChild()

repeat wait() until game.Players.LocalPlayer.Character
repeat wait() until game.Players.LocalPlayer.Character:IsDescendantOf(game.workspace)
wait(1 / 20)
-- the code above will repeat until the Player's Character is in game.Workspace and in Players
-- WaitForChild:() is basically like :FindFirstChild(), but it waits until it finds the string name. If it doesn't, you get a error saying, 'infinite yield possible..'

game.Players.LocalPlayer:WaitForChild("leaderstats") -- because it waits a while before it loads

local Player = game.Players:WaitForChild(game.Players.LocalPlayer.Name)
local Item = game.ReplicatedStorage:WaitForChild("BombosSurvivalKnife")

local Button = script.Parent
local Cost = 1000
local Money = Player.leaderstats.Robux

Button.MouseButton1Down:connect(function(purchase)
    if Money.Value > (Cost - 1) then
        Money.Value = Money.Value - Cost
        local a = Item:Clone()
        a.Parent = Player.Backpack
        local b = Item.Clone()
        b.Parent = Player.StarterGear
    end
end) 

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