local badgeservice = game:GetService("BadgeService")
local id = 2141551581 --Put your id here
local serverScriptService = game:GetService("ServerScriptService")
local debounce = false
local Cooldown = 30 --Cooldown for avoid spam from Touched Event
local Part = script.Parent
Part.Touched:Connect(function(HitPlr)
if debounce then return end
debounce = true
--BadgeGiver--
if HitPlr.Parent:FindFirstChild("Humanoid") and game.Players:FindFirstChild(HitPlr.Parent.Name) then
local Player = game.Players[HitPlr.Parent.Name]
if not game:GetService("BadgeService"):UserHasBadgeAsync(Player.UserId, id) then
badgeservice:AwardBadge(Player.UserId, id)
game.ReplicatedStorage.SendChatEvent2:FireAllClients(Player.Name.. " defeated the Effortless Difficulty!" );
end
end
--Cooldown
task.wait(Cooldown)
debounce = false
end)
It’s inside the part and essentially, when someone goes over the part, they get the badge and a chat message will pop up saying that they passed a certain difficulty. The only bug with this script is that, when someone else is on the part and triggers the event, if someone else comes by in that timeframe, they won’t get the badge. I know it is because of the cooldown but I set it that high so the chat isn’t spammed with messages saying they passed that certain difficulty. Is there a way to make it so that the script only affects the one person and not the entire server? (I tried making this a local script but it didn’t work)
local BS = game:GetService("BadgeService")
local ID = 2141551581
local StageDifficults = {
["Effortless"] = 25,
["Easy"] = 50,
['Medium'] = 95,
}
game.Players.PlayerAdded:Connect(function(plr)
plr.leaderstats.stage.Changed:Connect(function()
if StageDifficults[plr.leaderstats.stage] then
BS:AwardBadge(plr.UserId, ID)
print(plr.. "defeated "..StageDifficults[1])
end
end)
end)
Sorry for the late reply. I was testing out a lot of different variations of the script. The script works, it is just that, I already have a leaderstats and everything so by calling it again in the script, it erases the one I already have. Is there a way to call to my leaderstats I already have without creating a new leaderstats?
Edit: The script works, just not personally for what I need but I’ll still mark that as a solution in case anyone else needs the same help! Thanks for your help as well.
Just get the lines of code that create your leaderstats, and replace the existing lines in this .PlayerAdded event with them (and make sure to delete them from the script that they were originally in) then replace the “Stage” here: “if StageDifficults[Stage.Value] then” and here: "print(plr.Name…"Has defeated "…StageDifficults[Stage.Value])"with the name of the IntValue that you already created.
And of course you can access it from any other script. (Just to make sure though, make sure to check it exists first.)
The lines of code that create my leaderstats also control my checkpoints for my obby. I would remove it but that script itself is very lengthy and I would not know how to rewrite it without the leaderstats. As I mentioned before, is there a way to make a call to the leaderstats without rewriting them completely? I do appreciate the help
Oh alright, well you can try removing the 6 lines that create the leaderstats in this .PlayerAdded event, and then write this at the top (still in the .PlayerAdded event)
local leaderstats = plr:WaitForChild(“leaderstats”)
local Stage = leaderstats:WaitForChild(“NameOfTheIntValue”) --Change the text inside the string to the name of your IntValue
Thank you for your help! I ended up messing around with the script some more and also found another forum post that helped me alot. Here is the link to the post if anyone needs more help as well