VehicleSeat badge detector producing errors

I want a vehicle to only be accessible to users with a specific badge. However, the script in question produces multiple errors when the seat is used.

image

I have tried looking for solutions on the developer hub, the DevForum, and even YouTube. Unfortunately, I was unable to find anything particularly useful on either of these platforms.

The script is written as follows, and it is placed within the VehicleSeat. It was originally a Game Pass detection script, which worked quite well.

local badgeId = 2124644447

local BadgeService = game:GetService("BadgeService")
local PlayersService = game:GetService("Players")

function isAuthenticated(player)
    return BadgeService:UserHasBadgeAsync()(player.UserId, badgeId)
end

script.Parent.ChildAdded:Connect(function(obj)

    if obj.Part1.Name ~= "HumanoidRootPart" then return end

    local plr = PlayersService:GetPlayerFromCharacter(obj.Part1.Parent)

	print(string.format("%s attempted to operate Transperceneige.", plr.Name, script.Parent.Parent.Name))

	    if plr and not isAuthenticated(plr) then
		script.Parent.Disabled = true
		wait(1)
		script.Parent.Disabled = false
		print(string.format("%s is not authorized to operate Transperceneige.", plr.Name))
    end
    
end)

Any and all help is much appreciated!

1 Like

It’s probably an issue with this argument, can I see the explorer and the location of the script?

This part of the script works fine, as it is supposed to print the player’s name and what they tried to drive.

image

Were the double parentheses intentional?

I believe I used autocomplete to put in UserHasBadgeAsync and I forgot to remove them.

That’s probably the issue then.

It works perfectly now, thank you so much!

1 Like