Answered by
6 years ago Edited 6 years ago
You will want to check if the player has the gamepass using gamepass service https://wiki.roblox.com/index.php?title=API:Class/GamePassService/PlayerHasPass
You will want to check if they touched the door using the .Touched event which is fired when a basepart is touched. https://wiki.roblox.com/index.php?title=API:Class/BasePart/Touched
And to get the player from the character we will use https://wiki.roblox.com/index.php?title=API:Class/Players/GetPlayerFromCharacter
Also to kill the player we will use :BreakJoints() since it kills the player. I prefer :BreakJoints() over setting the health to zero since it takes less referencing.
Alright lets get coding.
(In this case we will put the script inside the door instance)
01 | local gamepassService = game:GetService( "GamePassService" ) |
02 | local players = game:GetService( "Players" ) |
03 | local door = script.Parent |
04 | local gamepassID = 123456789 |
07 | local function gamepassCheck(player) |
08 | if not gamepassService:PlayerHasPass(player, gamepassID) then |
09 | player.Character:BreakJoints() |
13 | local function doorTouched(hit) |
17 | local player = players:GetPlayerFromCharacter(hit.Parent) or players:GetPlayerFromCharacter(hit.Parent.Parent) |
27 | door.Touched:Connect(doorTouched) |
Make sure to change the gamepass to the ID you are using. (Tell me if the script has any problems.)