New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
-1

# will this script work not answered?

Asked by 5 years ago

will this pass work wean it is finshed because i dont know how to add it to the script for the ristricted door i want this door to work with a pass will this work or is there an eaiser way to do this

local door = script.Parent

function open() -- This function will open the door. door.CanCollide = false -- Make players able to walk through the door.

for transparency = 0, 1, .1 do
door.Transparency = transparency
wait(.1)
end


end

function close() -- This function will close the door. for transparency = 1, 0, -.1 do door.Transparency = transparency wait(.1) end

door.CanCollide = true -- Make players unable to walk through the door.


end

-- This function returns the player a certain part belongs to. function get_player(part) --iterate over each player for _, player in ipairs(game.Players:GetPlayers()) do --if the part is within the player's character if part:IsDescendantOf(player.Character) then --return the player return player end end end

door.Touched:connect(function(part) -- If it isn't a character that touched the door, then we ignore it. local player = get_player(part) if not player then return end

local allow = (
player.Name == "XlaonX" or
player.Name == "upbeatxxninjaxx" or
player.Name == "charlesannals" or
player.Name == "" or
player:HasPass(213801608) or         **Will this part on this line work for the vip pass**
game.CreatorId == player.userId
)
if allow then
open()
delay(4, close)
end


end)

2
Answered by 5 years ago

Sadly, the code you are currently using will not work, as there are a few problems;

1. Your third code block; You are attempting to use parentheses for a Table

2. Again, your third code block, line 9; You are attempting to see if 'allow' is true, as if your trying to check if the person is allowed [Which may be what your trying to do

3. ONCE again, back to the third code block, line 1 again, there are multiple problems in that code there;

a. What you are trying to do is set the Player's name, you are not checking the name!

b. It is not properly checking through, it's saying Check Condition or Condition or Condition or Condition or ect., thus, it's not going through properly!

c. player:HasPass is not a valid Method, which will cause an error!

This can all be fixed, however, I do not understand what you are trying to do; Some code is not in a .lua block, and your not telling us whats wrong/ giving us any Output!

Now, let's fix your code;

local PeopleAllowed = {} --Here is our 'Table', as I have mentioned before

function Allowed(plr) --Here is our new function to check if the Player is allowed
for i = 1, #PeopleAllowed do --This will loop through the table 'PeopleAllowed'
if plr.Name:lower() == PeopleAllowed[i]:lower() then --If the Player's name matches to, well, PeopleAllowed[i] [Meaning the string in the table]
return true --Returns true if so, allowing the code to go on
end --This ends the code block for the 'if' statement
end --This ends the code block for the 'for' loop
return false --Returns false, not allowing the execution if the Player's name does not match
end --This ends the code block for the function


Now, let me bring up something else; It is not necessary to use two Functions to open and close your door, as you CAN do it into one function. Now, let's fix that;

local door = script.Parent --Identifier 'door' is not specifying/identifying the Script's Parent [The object-instance it is in]
local debounce = false --This will keep the code from firing multiple time onTouch

function Door(hit) --Here is our 'function' that will open/close the door
if not hit.Parent or debounce then return end --This checks to see if 'hit.Parent', or 'debounce' is equal to true [If condition equals to argument]
debounce = true --Will set 'debounce' to true to keep the function from firing multiple times
for i = door.Transparency, 1, 0.032 do --This will get 'door''s Transparency, and add it up by '0.032' until it reaches to '1'
door.Transparency = i --Will revert 'door''s Transparency property to 'i'
wait(1/44) --Waits 1/44 of a second before running again
end --This end the code block for the 'for' loop
door.CanCollide = false --Sets 'door''s CanCollide property to 'false', allowing the user to pass through
wait(32/19+2.5) --Waits 32/19 of a second [Is that event possible?! :O] before going on to the next block of code
for i = door.Transparency, 0, -0.032 do --Will get 'door''s Transparency, and subtract by '0.032' until it reaches to '0'
door.Transparency = i --Will revert 'door''s Transparency property to 'i'
wait(1/44) --Waits 1/44 of a second before running again
end --This ends the code block for the 'for' loop
door.CanCollide = true --Doesn't allow the user to pass through
debounce = true --Allows the user to use the door again
end --This ends the code block for the 'function'


Now, with the current codes we have, we can indeed, use these two;

local PeopleAllowed = {"charlesannals","friend"} --As you may not have known, you DO NOT use the 'or' operator to separate 'strings' in a 'table'!
local door = script.Parent
local debounce = false

function Allowed(plr)
for i = 1, #PeopleAllowed do
if plr.Name:lower() == PeopleAllowed[i]:lower() then
return true
end
end
return false
end

function Door(hit)
if not hit.Parent or debounce or not game.Players:GetPlayerFromCharacter(hit.Parent) then return end --This will check to see if 'hit.Parent' is not existant, 'debounce' is true, or the Player is not a real 'Player', and if either is 'true' to the 'if' statement, then it will return, and not let the code run/go on
local plr = game.Players:GetPlayerFromCharacter(hit.Parent) --Identifier 'plr' identifies the real 'Player'
if not Allowed(plr.Name) then return end --This will check to see if the Player's name is in the list, if not, then it not not allow the code to run/go on
debounce = true
for i = door.Transparency, 1, 0.032 do
door.Transparency = i
wait(1/44)
end
door.CanCollide = false
wait(32/19+2.5)
for i = door.Transparency, 0, -0.032 do
door.Transparency = i
wait(1/44)
end
door.CanCollide = true
debounce = true
end


Hope this helped!