I attempted to make a teleport script that would teleport any player with said badge to another place upon touch, and it does not appear to be working. I get the error message “Workspace.Door.Script:3: attempt to index nil with ‘Parent’” in terminal. Any ideas?
badgeId = 2124634329 -- Some random badge I own
local TeleportService = game:GetService("TeleportService")
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Place = 3233893879 -- Game with the badge
function badgeVip(hit)
local h = hit.Parent:findFirstChild("Humanoid")
if h ~= nil then
local plyr = game.Players:GetPlayerFromCharacter(hit.Parent)
badge = game:GetService("BadgeService")
if plyr ~= nil then
if badge:UserHasBadge(plyr.userId, badgeId) then
TeleportService:Teleport(Place, player)
else
h.Health = 0 end
end
end
end
script.Parent.Touched:connect(badgeVip)
“hit” is not defined on line 3. Although I don’t think you even need that line anyway since you are using “plyr” instead. You would just need to replace “player” with “plyr” in the Teleport method too.
Hello!
You are trying to define the touching player before he actually touches!
So youu should remove this line: local player = game.Players:GetPlayerFromCharacter(hit.Parent) (it’s the 3rd line of your code).
Also when I look on your script I see you are using game.Players. It is not really a good practice. Please consider changing it to game:GetService("Players").