Brick gives the player a win + coins and the badge when touched and is also supposed to teleport the player back to the lobby, however it doesn’t always teleport the player back.
tp = game:GetService("TeleportService")
db = true
badge1 = game:GetService("BadgeService")
script.Parent.Touched:Connect(function(hit)
player = game.Players:GetPlayerFromCharacter(hit.Parent)
if db == true and player ~= nil then
db = false
player.PlayerGui.choppa:Destroy()
badge = 2124480977
local msgui = script.Parent.blank1:Clone()
msgui.Parent = player.PlayerGui
player.leaderstats.Wins.Value = player.leaderstats.Wins.Value + 1
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 10
player.Character:MoveTo(Vector3.new(-6886.81, 495.181, -273.92))
Victory = Instance.new("Sound",player)
Victory.SoundId = "rbxassetid://713824288"
Victory:Play()
wait(1.5)
db = true
Victory:Destroy()
helicop = Instance.new("Sound",player)
helicop.SoundId = "rbxassetid://165113352"
helicop:Play()
helicop.Volume = 0.5
wait(7)
tp:Teleport(3329479830,player)
end
end)
print("Badge Awarder Loaded. BadgeID: " .. script.Parent.BadgeID.Value)
function OnTouch(part)
if (part.Parent:FindFirstChild("Humanoid") ~= nil) then
local p = game.Players:GetPlayerFromCharacter(part.Parent)
if (p ~= nil) then
print("Awarding BadgeID: " ..script.Parent.BadgeID.Value .. " to UserID: " .. p.userId)
local b = game:GetService("BadgeService")
b:AwardBadge(p.userId, script.Parent.BadgeID.Value)
end
end
end
script.Parent.Touched:connect(OnTouch)
This is just a guess, but can you try using this version? I also cleaned up your code a bit and mainly added some sanity checks so the Code should not break in case somethings missing.
local TeleportService = game:GetService("TeleportService")
local db = true
local BadgeService = game:GetService("BadgeService")
local BadgeId = 2124480977
local PlaceId = 3329479830
print("Badge Awarder Loaded. BadgeID: " .. BadgeId)
function OnTouch(part)
if part.Parent:FindFirstChild("Humanoid") ~= nil then
local Player = game.Players:GetPlayerFromCharacter(part.Parent)
if Player ~= nil then
print("Awarding BadgeID: 2124480977 to UserID: " .. Player.UserId)
BadeService:AwardBadge(Player.UserId, BadgeId)
if db == true then
db = false
local PlayerGui = Player:FindFirstChildWhichIsA("PlayerGui")
local Leaderstats = Player:FindFirstChild("leaderstats")
if PlayerGui:FindFirstChild("choppa") then
PlayerGui.choppa:Destroy()
end
if script.Parent:FindFirstChild("blank1") then
local MSGui = script.Parent.blank1:Clone()
MSGui.Parent = PlayerGui
end
if Leaderstats:FindFirstChild("Wins") then
Leaderstats.Wins.Value = Leaderstats.Wins.Value + 1
end
if Leaderstats:FindFirstChild("Coins") then
Leaderstats.Coins.Value = Leaderstats.Coins.Value + 10
end
if Player.Character then
Player.Character:MoveTo(Vector3.new(-6886.81, 495.181, -273.92))
end
local Victory = Instance.new("Sound")
Victory.SoundId = "rbxassetid://713824288"
Victory.Parent = PlayerGui
Victory:Play()
wait(1.5)
db = true
local Chopper = Instance.new("Sound")
Chopper.SoundId = "rbxassetid://165113352"
Chopper.Parent = PlayerGui
Chopper:Play()
wait(7)
print("Teleporting Player")
TeleportService:Teleport(PlaceId, Player)
end
end
end
end
script.Parent.Touched:Connect(OnTouch)