would like to create a script that awards a badge to players who join any server in my game except the one im currently in when my userId is 4092285006 is in any server. Im trying to award the badge (Badge id: 2151451557).
. I am trying to create a script that detects if the player with userId 4092285006(my user Id) is in a server other than the one a different player is in. I want to award that the badge only when another player joins a different server from mine.
I’ve tried several script variations to achieve this behavior, but none have the correct results. I have also looked at the Developer Hub for information but couldn’t find a solution.
Couldn’t you just check when a player joins then if your in the game it doesn’t award?
local UserId = 4092285006
local BadgeId = 2151451557
local BadgeService = game:GetService('BadgeService')
game.Players.PlayerAdded:Connect(function(player)
local Name = game.Players:GetNameFromUserIdAsync(UserId)
if game.Players[Name] then
return
end
BadgeService:AwardBadge(player.UserId,BadgeId)
end)
local UserId = 4092285006
local BadgeId = 2151451557
local BadgeService = game:GetService('BadgeService')
game.Players.PlayerAdded:Connect(function(player)
local Name = game.Players:GetNameFromUserIdAsync(UserId)
if game.Players:FindFirstChild("Roblox") then--change roblox to ur username
BadgeService:AwardBadge(player.UserId,BadgeId)
end
end)
local Players = game:GetService("Players")
local Teleport = game:GetService("TeleportService")
local Badges = game:GetService("BadgeService")
Players.PlayerAdded:Connect(function(player: Player)
local success, errorfailed, placeid,jobid
local yeah, FAIL = pcall(function()
success, errorfailed, placeid, jobid = Teleport:GetPlayerPlaceInstanceAsync(Players:GetUserIdFromNameAsync("AJjIsCOoLs"))
end)
if yeah then
if placeid == game.PlaceId then
xpcall(function(...)
Badges:AwardBadge(player.UserId,2151451557)
end,function(a0)
print(tostring(a0))
end)
end
end
end)
Try this it uses messaging service for cross server communication:
local OwnerIsInGame = false
local UserId = 4092285006
local BadgeId = 2151451557
local BadgeService = game:GetService('BadgeService')
local MessagingService = game:GetService('MessagingService')
MessagingService:SubscribeAsync("Owner",function(msg)
OwnerIsInGame = msg.Data
end)
game.Players.PlayerAdded:Connect(function(player)
local Name = game.Players:GetNameFromUserIdAsync(UserId)
if player.UserId == UserId then
MessagingService:PublishAsync("Owner",true)
end
if OwnerIsInGame then
BadgeService:AwardBadge(player.UserId,BadgeId)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
if player.UserId == UserId then
MessagingService:PublishAsync("Owner",false)
end
end)