Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Gamepass Script (Pass Through Block) Not Working?

Hi everyone. I've been scripting something that lets players with a certain gamepass go through a block. (Special thanks to ABK2017 for yesterday's help). If the player does not own the gamepass, it will teleport them a few blocks back. The script works for me in studio, but for some reason, breaks in-game. I am able to go through the blocks with the script a few times until eventually they will teleport me back, despite owning the gamepass. Could anyone help with this? I have a picture of my current script below. https://imgur.com/a/YWAd9Gz

1 comment

0

I answered your question. Hope it helps!

1 answer

✓ Accepted answer

There are several problems with your code and I am going to address them all if possible. First of all there is a function called :GetPlayerFromCharacter(). Here is how you can use it:

local players = game:GetService("Players") -- getservice is the recommended method for getting services like players
door.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then -- if it is a player touching
		local player = players:GetPlayerFromCharacter(hit.Parent)
	end
end)

Also open() and close() are unnecessary functions. Just use door.CanCollide = true and door.CanCollide = false You do not need a second event listener once you determine whether or not a player has a gamepass. I am speaking about the new event listener on line 28. Just immediately teleport the player back because you already know they don't have the gamepass and that they are a player. I do not understand why you have a table on line 20. I am assuming you want to have the table in case there is more than one gamepass later on. Either way the if statement on line 24 will always pass. Why? Because a table is truthy. You will have to access the index of the gamepass checker like so: if allow[1] then I hope that all of these comments help and that you are able to fix your problem. Have a great day scripting!

This discussion is preserved as it was. New answers, comments, and votes are closed.