Script to check if player has badge then changes a datastore value, doesn't work

Im trying to check if the player is added, to add the LocalPlayer variable
Though it doesn’t work, there isnt an output error aswell.

local b = game:GetService("BadgeService")


-- EDIT THIS--

local datavalue = "HasEggdog"

game.Players.PlayerAdded:Connect(function(plr)
	local checker = plr:WaitForChild('Data'):WaitForChild(datavalue).Value
	local badgeid = script.Parent.BadgeID.Value

	if b:UserHasBadgeAsync(plr.UserId, badgeid) then
		print(plr.Name .. " has badge " .. badgeid)
		checker = true
	else
		checker = false
	end
end)

I have changed a bit of the code around.

EDIT I forgot to mention this:
This code will check if the player has the badge and if the player does it prints a message in the output, if the player doesn’t, it will print a different message in the output. This coding example may help so you can implement your own system into this coding example I have provided.

Basic Example:

local badgeService = game:GetService("BadgeService")
local players = game:GetService("Players")

local badgeID = 123456 -- Enter your badge ID here

players.PlayerAdded:Connect(function(player)
    if badgeService:UserHasBadgeAsync(player.UserId, badgeID) then
        print("Has badge")
    else
        print("Does not have badge")
    end
end)

image
This datastore value didnt change

Try this:

local b = game:GetService("BadgeService")


-- EDIT THIS--

local datavalue = "HasEggdog"

game.Players.PlayerAdded:Connect(function(plr)
	local checker = plr:WaitForChild('Data'):WaitForChild(datavalue)
	local badgeid = script.Parent.BadgeID.Value

	if b:UserHasBadgeAsync(plr.UserId, badgeid) then
		print(plr.Name .. " has badge " .. badgeid)
		checker.Value = true
	else
		checker.Value = false
	end
end)
1 Like

Yippie! that worked! Tysm bro!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.