I'm a newbie at scripting and I've been trying to make a code to buy items upon clicking a dialog and having the money for it. Here is the code for the dialog
local dialog = script.Parent.Parent
local choice1 = dialog.DialogChoice.KatanaChoice
local user = --how can I find the user that clicked the dialog here?
local stats = user:findFirstChild("leaderstats")
local bank = stats:findFirstChild("Bank")
local cash = stats:findFirstChild("Cash")
dialog.DialogChoiceSelected:connect(function(plr, choice)
if choice == choice1 then
if cash.Value >= 25000
or bank.Value >=25000 then
local katana = game.Lighting.Katana:clone()
katana.Parent = plr.Backpack
local choice2 = dialog.DialogChoice.RocketChoice
if choice == choice2 then
if cash.Value >= 100000
or bank.Value >= 100000 then
local Rocket = game.Lighting.RocketLauncher:clone()
Rocket.Parent = plr.Backpack
local choice3 = dialog.DialogChoice.SpinnerChoice
if choice == choice3 then
if cash.Value >=500000
or bank.Value >=500000 then
local Spinner = game.Lighting.AutisticShuriken:clone()
Spinner.Parent = plr.Backpack
local choice4 = dialog.DialogChoice.PistolChoice
if choice == choice4 then
if cash.Value >=8000
or bank.Value >=8000 then
local Pistol = game.Lighting.GLOCK18:clone()
Pistol.Parent = plr.Backpack
end
end
end
end
end
end
end
end
end
)
And here is the code for the leaderboard (free model)
function onPlayerEntered(newPlayer)
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
local c = Instance.new("IntValue")
c.Name = "Cash"
c.Value = 50000
c.Parent = stats
stats.Parent = newPlayer
local b = Instance.new("IntValue")
b.Name = "Bank"
b.Value = 10000
b.Parent = stats
stats.Parent = newPlayer
newPlayer.Changed:connect(function (property)
if (property == "Character") then
onPlayerRespawned(newPlayer)
end
end)
end
game.Players.ChildAdded:connect(onPlayerEntered)

4 comments
I greatly appreciate the help but it does not seem to work still. I've ensured that the dialog responses are the correct names but it doesn't give the item nor deduct money
Sorry about that, I fixed the code, you just need to make sure that the name of the DialogChoice objects are named exactly like the variables at the top of the script
It worked! Thank you so much.
Happy to have helped :)