Trying to make a GUI Shop that let you Buy Badges

Hey developers!
I was trying to make a Shop/GUI that you can buy a badge with “Points” But my script isn’t working, It’s supposed when you click a TextButton award a badge by your number of points
I’m not that good scripting so I need help, what I’m doing wrong?

Latest try
 local player = game.Players.LocalPlayer
    local enabled = true
    local BadgeID = 100000 -- This is just a example
    	script.Parent.MouseButton1Click:Connect(function()
    			if enabled == true then
    			enabled = false
    		if 	player:FindFirstChild("leaderstats").Points>=40 then
    			player:FindFirstChild("leaderstats").Points.Value = player:FindFirstChild("leaderstats").Points.Value - 40
    			game:GetService("BadgeService"):AwardBadge(player.userId,BadgeID)
    			wait(1)
    			enabled = true
    			end
    		end
    	end)

Yes I’m using my badge ID that was just an example
Sorry this part didn’t appear in the Summary Player:FindfirstChild("leaderstats").Points.Value - 40`

4 Likes

You tried to assign a value with a instance.

1 Like

= Higuer Than
< = Less Than

Simple right?

Here’s a “fixed” version of the code:

local plr = game.Players.LocalPlayer
local debounce = false
local BadgeID = 100000 -- This is just a example

script.Parent.MouseButton1Click:Connect(function()
	if debounce == false then
		debounce = true
		if 	plr:FindFirstChild("leaderstats").Points.Value >= 40 then -- Checks if the amount of Points inside of the leaderstats is higuer/equal than/to 40.
			plr:FindFirstChild("leaderstats").Points.Value -= 40 -- Same as using plr:FindFirstChild("leaderstats").Points.Value = plr:FindFirstChild("leaderstats").Points.Value - 40
			game:GetService("BadgeService"):AwardBadge(plr.UserId, BadgeID)
			wait(1)
			debounce = false
		end
	end
end)
1 Like

also, I recommend using RemoteEvents for security

Wouldn’t that make it “worse”? Depending on how it is made, that is.

It’s a measure against exploiters because if this is in a localscript, they can change the value of the required points

Couldn’t they just change the amount of points they have in their leaderstat…?

How does that matter? It still is considered cheating/bypassing/exploiting.

They can but it depends on what their intentions are

I know. It’s just something to prevent them from cheating. They can only change values on the client, so if they change their points in leaderstats, only their client will see it and not the server

Thank you all for your help
For Fixing my code and grant me wisdom

I know

Well thanks for remind me not to lower my guard against exploiters I know their intentions.

2 Likes

He used a LocalScript to check whether or not the players that try to buy a badge have a certain amount of money, meaning the client would accept and let the exploiter have the badge…

Actually, I’ll just leave this here: Exploiting Explained

1 Like

I know. I’m just saying if you want to, you can add security

1 Like

I added my badge ID and
For some reason isn’t awarding badge, But it actually removes my points
I should do a RemoteEvent to award badge?

1 Like

Make a RemoteEvent, then put this in the local script.

Local script :

local badgeId = --badgeid
local debounce = false
script.Parent.MouseButton1Click:Connect(function(player)
    if not debounce then
        debounce = true
        game.ReplicatedStorage.RemoteEvent*:FireServer(badgeId)
    end
end) 

“*”: Your event name.

Server Script :

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, badgeId)
    if player:FindFirstChild("leaderstats").Points.Value >= 40 then
        player:FindFirstChild("leaderstats").Points.Value -= 40
        game:GetService("BadgeService"):AwardBadge(player.UserId, BadgeID)
    end
end)
4 Likes