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

How to make a NPC give items using leaderboard cash?

local dialog = script.Parent
dialog.DialogChoiceSelected:connect(function(player, choice)
    local stats = player:FindFirstChild('leaderstats')
    if not stats then return end
 
    local old = stats:FindFirstChild('Cash')
    if not Cash then return end
 
    if choice == script.Parent.DialogChoice.ChoiceA then
        if Cash.Value >= 500 then 
            game.ReplicatedStorage.Weapon1:Clone().Parent = player.Backpack
            Cash.Value = Cash.Value - 500 
        end
    

I want this script to give a "Bat" when you speak to it and have enough money. I have this script and its inside the NPC's head any suggestions: Here are some more screenshots of what i've done:

https://gyazo.com/209d495e015dbdb196a63d29b9c62455

https://gyazo.com/89ee2978f88f78b78c5e5c6e5984637d

1 answer

Line 6's variable name is old, but you then use Cash on line 7.

If you open up the Script Analysis window in Roblox Studio, it will tell you when you use variables that aren't defined elsewhere.

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