Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

attempt to compare number with string (?)

Asked by 6 years ago
Edited by BlueTaslem 6 years ago
-- 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) 
0
Is Money a stringvalue? You could try if tonumber(Money.Value) > (Cost - 1) then Vulkarin 581 — 6y
0
edited to fix code block BlueTaslem 18071 — 6y

1 answer

Log in to vote
0
Answered by
hellmatic 1523 Moderation Voter
6 years ago
Edited 6 years ago

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) 
Ad

Answer this question