Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I kill a person when they dont have a gamepass touching a door?

Asked by 6 years ago

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

0
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 BlueTaslem 18071 — 6y

2 answers

Log in to vote
0
Answered by
Async_io 908 Moderation Voter
6 years ago
Edited 6 years ago

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

Ad
Log in to vote
0
Answered by
hellmatic 1523 Moderation Voter
6 years ago
Edited 6 years ago

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)

Answer this question