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 this script check leaderboard enough money then take that amount?

Please help make it so this script first checks leaderboard stats to see if you have enough money or more then take that amount and finish the rest of the code (please do not make it so it gives the item i just need it so it checks if player has enough money and takes that amount!)

script.Parent.MouseButton1Click:connect(function() if not game.Players.LocalPlayer.Backpack:FindFirstChild("SpeedCoil") then print("Giving "..game.Players.LocalPlayer.Name.." Item.") Sword = game.Lighting.SpeedCoil:Clone() Sword.Parent = game.Players.LocalPlayer.Backpack elseif game.Players.LocalPlayer:FindFirstChild("SpeedCoil") then print(game.Players.LocalPlayer.Name.." Already received the item.") end end)

Thank you for your time! Please help me out!

3 comments

0

place your code in a code block pls

0

Maybe I Can Figure That Out! Mind If I Share You Another Script?

0

Do not use lighting as storage.

1 answer

Hello, thekittinking84!

All you have to do is pretty simple, so i have edited the script for you :)


local cost = 45

script.Parent.MouseButton1Click:connect(function()
 if not game.Players.LocalPlayer.Backpack:FindFirstChild("SpeedCoil") and game.Players.LocalPlayer.leaderstats.Money >= cost  then -- Note : you have to place a folder named "leaderstats" with an IntValue named "Money" inside the folder, now the folder has to be inside the player ( not backpack ).

game.Players.LocalPlayer.leaderstats.Money = game.Players.LocalPlayer.leaderstats.Money - cost

 print("Giving "..game.Players.LocalPlayer.Name.." Item.")
 Sword = game.Lighting.SpeedCoil:Clone()
 Sword.Parent = game.Players.LocalPlayer.Backpack

 elseif game.Players.LocalPlayer.Backpack:FindFirstChild("SpeedCoil") then print(game.Players.LocalPlayer.Name.." Already received the item.")


 end
 end)

Here, put this script in ServerScriptService :/

local stats = script.leaderstats:Clone() -- Make sure that you have done the things in the last note, but this time place the folder INSIDE this script, and you are done!

game.Players.PlayerAdded:Connect(function(player)
stats.Parent = player
    end)
  • Accept the answer if this helped!

-- Hope i helped.

--- Edited!

---- AIphanium

2 comments

0

It doesn't seem to be working but im new could i have a screenshot to see where i have to put the leaderstats folder?

0

Edited my answer.

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