I’m trying to get a script that can save as a “datastore”, so if a player joins and they have a certain badge, a GUI will show. kind of like find the markers saving system!
I’m sure how to start scripting this because I am kind of new, so any help is appreciated!
Hi, welcome to Lua scripting! You can easily do this by using the BadgeService, more specifically its UserHasBadgeAsync method. Here’s basic implementation:
local badgeService = game:GetService("BadgeService")
local myBadge = 123 --Your badge ID here
game.Players.PlayerAdded:Connect(function(player)
if badgeService:UserHasBadgeAsync(player.UserId, myBadge) then
--your code for showing the gui here
end
end)
I changed the script to fit with the LocalPlayer (this game is multiplayer), but it still did not work. Unless I messed up with the local.
Here’s the script I’m using:
local players = game:GetService("Players")
local player = players.LocalPlayer
local badgeService = game:GetService("BadgeService")
local myBadge = 2128479656
game.Players.PlayerAdded:Connect(function(player)
if badgeService:UserHasBadgeAsync(player.UserId, myBadge) then
player.PlayerGui.ScreenGui.ListOfJackeryz.Jackeryz.checkmark.Visible = true
end
end)
That’s because you’re connecting to the player joining action, and LocalScripts execute after the player joins. Modify your script as so:
local players = game:GetService("Players")
local player = players.LocalPlayer
local badgeService = game:GetService("BadgeService")
local myBadge = 2128479656
if badgeService:UserHasBadgeAsync(player.UserId, myBadge) then
player.PlayerGui.ScreenGui.ListOfJackeryz.Jackeryz.checkmark.Visible = true
end
That way, upon joining, your LocalScript will get the current player, and check if they have the badge.