Whenever I try entering the door it would kill me and not let me in. Whats the problem here?
local Door = script.Parent local enter = 'duckyo01', 'Player' script.Parent.Touched:connect(function(hit) if hit.Parent then local hum = hit.Parent:FindFirstChild('Humanoid') if hum then if hum.Name == enter then Door.Transparency = 0.5 Door.CanCollide = false else hum.Health = 0 end end end end)
local Door = script.Parent local enter = 'duckyo01', 'Player' -- should be a table script.Parent.Touched:connect(function(hit) if hit.Parent then --everyhting has a parent besides game local hum = hit.Parent:FindFirstChild('Humanoid') if hum then -- no since should of been if hum if hum.Name == enter then -- enter has 2 values so. Door.Transparency = 0.5 Door.CanCollide = false else hum.Health = 0 end end end end)
local Door = script.Parent local allowed = {"duckyo01","Player"} script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") ~= nil then -- checks if the hit's parents found humanoid aka if it's a player local player = hit.Parent --variablize it accepted = false -- debouncer for i,v in pairs(allowed) do if v:lower() == player.Name:lower() then -- compares table naes to real accepted = true -- checked end if accepted == true then -- yo stuff after dis is right gg m8 Door.Trasnparency = .5 Door.CanCollide = false else hum.Humanoid.Health = 0 end end end)
One of ways you can increase your scripting efficiency is reducing the amount of if statement you use simply using and
. I suggest storing all your string inside a Table since it make your code looks a lot cleaner and nicer.
local Allowed = {"UserOnly16Characters","duckyo01","Player"}--Table Storing random strings. script.Parent.Touched:connect(function(Hit)--Function listen for the Touched event. local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)--Checks to see if the Part that triggered the function is controlled by a Player! local Access = false--Check for _, v in pairs (Allowed) do--Loops through the Tabled(Allowed) that we created. if v == Player.Name then--Check to see if any of the Strings in the table matches the Player/Object who triggered the event. Access = true--If it matches then this will be true. end end if Player and Access == true then--If the Part that triggered the function is controlled by a Player and is and is Allowed then script.Parent.Transparency = 0.5--Turns the Parts Transparency to 0.5 script.Parent.CanCollide = false-- Turns Parts the CanCollide false so the Player can go through the door. wait(3) script.Parent.Transparency = 0--Turns the Parts Transparency to 0 script.Parent.CanCollide = true--Make sure no one else that doesn't have access can go through the "Door". else Player.Character.Humanoid.Health = nil--If the Player isn't Allowed then He or she dies Muahah. xD end end)
Locked by User#5978 and HungryJaffer
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?