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`
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)
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
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…
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)