What Im triyng to achieve?
To make it when a player joins the game it gives them a badge.
when a player touched a part they get a badge when they have the touch badge already a gui pops up saying you have this already.
The issue is
its not giving badge and gui not poping
What I solutions have you tried so far?
i have tried the dev forums and the docs
my script in serverscriptservice btw
local PlayerService = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local BadgeModule = require(game.ReplicatedStorage.ModuleScripts.Badges.BadgesModuleScript)
local badgegive = game.Workspace.TouchBadge
local JoinBadgeID = BadgeModule.Badges["JoinBadge"]
local TouchBadgeID = BadgeModule.Badges["TouchBadge"]
local ST = game:GetService("StarterGui")
local heyGUI = ST.Hey
local heyText =ST.Hey.Frame.ItemsFrame.Items.HeyMessage
PlayerService.PlayerAdded:Connect(function(player)
wait(5)
print("JoinBadgeID:", JoinBadgeID)
print("TouchBadgeID:", TouchBadgeID)
if JoinBadgeID then
local playerHasJoinBadge = BadgeService:UserHasBadgeAsync(player.UserId, JoinBadgeID)
if not playerHasJoinBadge then
BadgeService:AwardBadge(player.UserId, JoinBadgeID)
print(player.Name .. " awarded with JoinBadge!")
else
print(player.Name .. " already has JoinBadge.")
end
else
warn("JoinBadgeID not found in BadgeModule.")
end
end)
badgegive.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
local TouchBadgeID = BadgeModule.Badges["TouchBadge"]
print("TouchBadgeID:", TouchBadgeID)
if TouchBadgeID then
if not BadgeService:UserHasBadgeAsync(plr.UserId, TouchBadgeID) then
BadgeService:AwardBadge(plr.UserId, TouchBadgeID)
print(plr.Name .. " awarded with TouchBadge!")
else
heyText.Text = "already has TouchBadge."
heyGUI.Enabled = true
print(plr.Name .. " already has TouchBadge.")
end
else
warn("TouchBadgeID not found in BadgeModule.")
end
end
end
end)```
Trying replacing these lines with these ones. The script loads before the parts and GUI. But Most importantly, you’re only altering the GUI in the StarterGui Folder, so if you get the badge, and then reset your character, you’ll see the message. The StarterGui instances get Cloned to the Player’s Gui folder. So you need to do something like this:
local PlayerService = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local BadgeModule = require(game.ReplicatedStorage.ModuleScripts.Badges.BadgesModuleScript)
local badgegive = game.Workspace.TouchBadge
local JoinBadgeID = BadgeModule.Badges["JoinBadge"]
local TouchBadgeID = BadgeModule.Badges["TouchBadge"]
PlayerService.PlayerAdded:Connect(function(player)
wait(5)
local heyGUI = player:WaitForChild("PlayerGui"):WaitForChild("Hey")
local heyText = heyGUI:WaitForChild("Frame"):WaitForChild("ItemsFrame"):WaitForChild("Items"):WaitForChild("HeyMessage")
print("JoinBadgeID:", JoinBadgeID)
print("TouchBadgeID:", TouchBadgeID)
if JoinBadgeID then
local playerHasJoinBadge = BadgeService:UserHasBadgeAsync(player.UserId, JoinBadgeID)
if not playerHasJoinBadge then
BadgeService:AwardBadge(player.UserId, JoinBadgeID)
print(player.Name .. " awarded with JoinBadge!")
else
print(player.Name .. " already has JoinBadge.")
end
else
warn("JoinBadgeID not found in BadgeModule.")
end
end)
badgegive.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
local TouchBadgeID = BadgeModule.Badges["TouchBadge"]
print("TouchBadgeID:", TouchBadgeID)
if TouchBadgeID then
if not BadgeService:UserHasBadgeAsync(plr.UserId, TouchBadgeID) then
BadgeService:AwardBadge(plr.UserId, TouchBadgeID)
print(plr.Name .. " awarded with TouchBadge!")
else
heyText.Text = "already has TouchBadge."
heyGUI.Enabled = true
print(plr.Name .. " already has TouchBadge.")
end
else
warn("TouchBadgeID not found in BadgeModule.")
end
end
end
end)