Welcome Badge and You Reached The End Badge not working

Hello Robloxians, i have trouble with the: End Badge Script. this script Gives you a Badge whenever you touch the last checkpoint of my obby.

here is my script:

Btw in output this error shows:
UserID is not a valid member of MeshPart “Workspace.wanuVC.RightLowerLeg” or leftlowerleg.

local endPad = game.Workspace.CheckPoints:FindFirstChild("13")

local BadgeID = 2141501193
local badgeservice = game:GetService("BadgeService")

endPad.Touched:Connect(function(plr)
	local owned = badgeservice:UserHasBadgeAsync(plr.UserID,BadgeID)
	
	if not owned then
		badgeservice:AwardBadge(plr.UserID,BadgeID)
	end
end)
3 Likes

That’s because you try to give a badge to a part of a player’s character.

This should work:

local endPad = game.Workspace.CheckPoints:FindFirstChild("13")

local BadgeID = 2141501193 -- Badge Id
local badgeservice = game:GetService("BadgeService")

endPad.Touched:Connect(function(plr) -- Check if the part has been touched
    local player = game.Players:GetPlayerFromCharacter(plr.Parent) -- get the player from a part of the player's character
	local owned = badgeservice:UserHasBadgeAsync(player.UserId,BadgeID) -- Check if the player has a badge
	
	if not owned then -- if the player doesn't own it then award the badge
		badgeservice:AwardBadge(player.UserId,BadgeID)
	end
end)
1 Like

i get this error:

GetPlayerFromCharacter is not a valid member of DataModel “Game”

1 Like

Please do not copy the code. That function belongs to the Players service.

1 Like

what does that mean? sorry im actually new to scripting and i keep failing at this one

and do you know a answer to my coding problem? it would really help

1 Like

Oh sorry now I noticed but in the script I typed:

local player = game:GetPlayerFromCharacter(plr.Parent)

instead of:

local player = game.Players:GetPlayerFromCharacter(plr.Parent)

If you copy the script again it should work

1 Like

this error i get:

UserID is not a valid member of Player “Players.wanuVC”

It is, UserId instead of UserID

This isn’t a very good Touched event, and the script @Mikixxx0 is providing isn’t helpful either

Your Issue is that you are Attempting to get a Property what Doesn’t exist within the Object you are looking through, This is because you have to check for the Object to ensure that it is what youre looking for, in this case, we will look for the Humanoid, A Component to our Characters that will help use Identify them, this is your Touched event:

endPad.Touched:Connect(function(otherPart)

Touched doesnt return a Player, It returns a BasePart if you read what It does:

Touched:Connect(func: (otherPart: BasePart) -> ()): RBXScriptConnection
  • The func part means it requires a function
  • The (otherPart: BasePart) means that the first argument is going to be a Part, not a Player
  • The : RBXScriptConnection is what’s being returned, which in this case, its the Signal used for the Event.

This will Help us understand what Touched does as now, we know that it returns a BasePart
BasePart is basically the class Part, MeshPart, WedgePart, etc can refer to, so any Part that touches the Object will be referred here.

In order to check if the Object we are getting is the Player’s Character, we have to do a multitude of things, which is to find the Humanoid of the Character, the reason we do this is so we can reference the Player.
But “we can do this without Having Errors!”, we use FindFirstChild, with FindFirstChild we can check if an Item exists within an Instance, if its not Found, it will return nil, otherwise it will return the Object, we can then check if the Item actually Exists using a simple if statement, here is an Example:
(Note that this Code block isnt Part of the Code, Just as an Example)

local Child = Instance:FindFirstChild("Child") -- Gets the Object named "Child"

if Child then -- if "Child" was found
    -- code here if the object was found
else
    warn"Child not Found!"
end

So now that we know how to do this, we can Check for the Humanoid:

local Hum = otherPart.Parent:FindFirstChildOfClass("Humanoid") -- Gets the First Humanoid in the Character

if Hum then -- If the Humanoid Exists
    -- code in a sec
end

We check the Parent of the Part because when something hits the endPart, it will return the Part, not the Model, with this check, we will be doing this:
OtherPart.Parent = Model
Model:FindFirstChild("Humanoid") (Humanoid or nil)

We then check if the Object is a Player or not by using GetPlayerFromCharacter as stated above.
What this will do is check if the Instance is the Character of a Player, if that is true, it will return a Player, otherwise, it will return nil, so like with the other Example, we will check if there is a Player:

local Hum = otherPart.Parent:FindFirstChildOfClass("Humanoid") -- Gets the First Humanoid in the Character
local Player = game.Players:GetPlayerFromCharacter(otherPart.Parent) -- checks the Model if its a Character for the Player

if Hum then -- If the Humanoid Exists
    if Player then -- if the Player was found
        -- Place your code here for the Badge
    end
end

So In total, you need to check for this stuff to make sure you are getting the Stuff you are looking for, this should be the full code:

endPad.Touched:Connect(function(otherPart) -- Event
    local Hum = otherPart.Parent:FindFirstChildOfClass("Humanoid") -- Gets the First Humanoid in the Character
    local Player = game.Players:GetPlayerFromCharacter(otherPart.Parent) -- checks the Model if its a Character for the Player

    if Hum then -- If the Humanoid Exists
        if Player then -- if the Player was found
            if not badgeservice:UserOwnsBadgeAsync(Player.UserId,BadgeID) then -- if User does not have the Badge
                badgeservice:AwardBadge(Player.UserId,BadgeID)
            end
        end
    end
end)
1 Like

fixed version

local endPad = workspace.CheckPoints:FindFirstChild("13")

local BadgeID = 2141501193
local badgeservice = game:GetService("BadgeService")
local debounce = false

endPad.Touched:Connect(function(plr)
	local plr = game.Players:GetPlayerFromCharacter(plr.Parent)
	if not plr then return end
	if not debounce then
		debounce = true
		
		local owned = badgeservice:UserHasBadgeAsync(plr.UserId, BadgeID)
		if owned then return end
		
		badgeservice:AwardBadge(plr.UserId, BadgeID)
		debounce = false
	end
	
end)
1 Like

This isn’t my script, its his script. I customized it to tell him what he did wrong. Please read carefully.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.