I am trying to kill a humanoid if they do not have a gamepass, but I cannot seem to find how to get a player id via humanoid
COMMUNITY QUESTION
How would I kill a person when they dont have a gamepass touching a door?
2 answers
If you're trying to get the Player ID (I'm assuming user id?) I would suggest using GetPlayerFromCharacter
It's pretty simple, first you start with game.Players followed by :GetPlayerFromCharacter then followed by parenthesis that are stored with the character. An example script would be:
local part = script.Parent
part.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
end
end)
Once you have the player defined, find the ID by using player.UserId
You can use Touched event
Place this in the door:
local Door = script.Parent
local RequiredId = 9999 -- your gamepass id
local Kill = true -- determines if the door can kill
function TOUCHED(hit)
if hit then
if game:GetService("Players"):FindFirstChild(hit.Parent.Name) then -- check if player
local player = game:GetService("Players"):FindFirstChild(hit.Parent.Name)
if player:IsA("Player") and CHECK_ACCESS(player) then
--code
elseif Kill then
player.Character:BreakJoints()
end
end
end
end
function CHECK_ACCESS(player)
if game:GetService("GamepassService"):PlayerHasPass(player, RequiredId) then
return true
else
return false
end
end
Door.Touched:connect(TOUCHED)
3 comments
0
thanks!
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
As a matter of game design, it might be better to not kill those players but simply not let them through, via local parts: http://wiki.roblox.com/index.php?title=Local_parts