Script help needed

I need help, heres my script.
game.Players.PlayerAdded:Connect(function(plr)
if plr.leaderstats.GoBux.Value >= 100 then
local clone = game.ServerStorage.Card2:Clone()
clone.Parent = plr.Backpack
end
end)

I’m trying to give a player a tool when they have a specific amount of Cash.

Any errors? you must show the problem before posting the problem.

1 Like

You are only checking when the player joins and not throughout their gameplay.

1 Like

Oh, thanks for pointing out the problem. How do I check the gameplay?

Oh sorry, this is my first ever post on the Devfourm.

RunService provides two loops that create barely any memory and performance leaks.

  1. the player might not have a leaderstats folder because they just joined
  2. if the player did have a leaderstats folder, the gobux variable would have a value of 0 by default. you need to load the value first, and then check if they have a certain amount of cash.
1 Like

How do I load the value and check their cash?

You would use WaitForChild, so the values can load in.

if plr:WaitForChild("leaderstats"):WaitForChild("GoBux").Value ~= nil then 
      if plr:WaitForChild("leaderstats"):WaitForChild("GoBux").Value >= 100 then 
       --- Do other stuff

dfwbhbhebhwe
:confused:

You put WaitForChild to “Replicated Storage” that’s why it infinite yield.

I didn’t even put anything in Replicated Storage.

You did WaitForChild to “Replicated Storage” not to “leaderstats”.

Note: Sorry I confuse you a little bit before my english is not that good.

How am I doing WaitForChild to ReplicatedStorage and not to leaderstats?

Nvm I found out the problem already.

You wrote game.ReplicatedStorage right?

Use DataStoreService! There are a bunch of tutorials on how to use it.