I want to make it so a player can only get a badge when they touch and part and they are still alive.
I’m not sure if the script I made would work or not.
I don’t think I would be able to get the answer just by looking on here but maybe I would be able to. I wasn’t sure if Scripting Support or Code Review was better for this. I just want to know if I made the script correctly so that it will only award the badge if the player touches the part and is still alive.
Here is the script:
local __BADGESERVICE = game:GetService("BadgeService")
local __PLAYERS = game:GetService("Players")
local __ID = 2140926703 -- !! REPLACE
script.Parent.Touched:Connect(function(__PART)
local __PLAYER = __PLAYERS:GetPlayerFromCharacter(__PART.Parent)
local humanoid = __PART.Parent:FindFirstChild("Humanoid")
if __PLAYER ~= nil and (not humanoid.Health) == 0 then
print("Here is your badge")
__BADGESERVICE:AwardBadge(__PLAYER.UserId, __ID)
end
end)
So would I need to make sure the script works by doing this?:
local __BADGESERVICE = game:GetService("BadgeService")
local __PLAYERS = game:GetService("Players")
local __ID = 2140926703 -- !! REPLACE
script.Parent.Touched:Connect(function(__PART)
local __PLAYER = __PLAYERS:GetPlayerFromCharacter(__PART.Parent)
local humanoid = __PART.Parent:FindFirstChild("Humanoid")
if __PLAYERS.character.humanoid then
if __PLAYER ~= nil and (not humanoid.Health) == 0 then
print("Here is your badge")
__BADGESERVICE:AwardBadge(__PLAYER.UserId, __ID)
end
end)
local __BADGESERVICE = game:GetService("BadgeService")
local __PLAYERS = game:GetService("Players")
local __ID = 2140926703 -- !! REPLACE
script.Parent.Touched:Connect(function(__PART)
local __PLAYER = __PLAYERS:GetPlayerFromCharacter(__PART.Parent)
local humanoid = __PART.Parent:FindFirstChild("Humanoid")
if not humanoid then
return end
if __PLAYER ~= nil and (not humanoid.Health) == 0 then
print("Here is your badge")
__BADGESERVICE:AwardBadge(__PLAYER.UserId, __ID)
end
end)