This script is not working and its not giving any error message

I am a begginer so sorry for the bad code

local clickDetector = script.Parent
local player = game.Players.PlayerAdded:Connect(function(plr)
local money = plr.leaderstats.Money
local replicatedStorage = game:GetService("ReplicatedStorage")

clickDetector.MouseClick:Connect(function(player)
money.Value = money.Value + 50
script.Parent.Parent:Destroy()

end)
end)

Can you format the code with a code block please? Also give some more information other than “my code isn’t working and I don’t know why”, because we don’t know what’s wrong with it without any information.

The code seems to be fine… You most likely just didn’t script the leaderstats correctly.

here’s the leaderstats

game.Players.PlayerAdded:Connect(function(plr)

local leader = Instance.new("Folder",plr)

leader.Name = "leaderstats"

local Money = Instance.new("IntValue",leader)

Money.Name = "Money"

end)

Ok, if this is a Normal ServerScript do this:

game.Players.PlayerAdded:Connect(function(plr)

local Folder = Instance.new("Folder", plr)
Folder.Name = "leaderstats"

local Cash = Instance.new("IntValue", Folder)
Cash.Name = "Money"
Cash.Value = 0

end)
1 Like

And put this inside what ever you click for the given value…

local clickDetector = script.Parent
local plr = game.Players.PlayerAdded or game:GetService("Players").LocalPlayer
local replicatedStorage = game:GetService("ReplicatedStorage")

	clickDetector.MouseClick:Connect(function(plr)
		plr.leaderstats.Money.Value += 50
		script.Parent.Parent:Destroy()
end)
1 Like