Hi, i have a Door Code script that works, i just need function when players enter the correct code, the door stay open only for them.
The door work perfectly, i just need a localscript for avoid player doesn't have code to cross the door in the same time of player have code ^^
The code:
Code = "9796" --change To any numbers You like Input = "" --This Is for my buddy siros --created by ------------------------------------------ --Clear And Enter function Clear() print("Cleared") Input = "" end script.Parent.Clear.ClickDetector.MouseClick:connect(Clear) function Enter() if Input == Code then print("Entered") Input = "" local door = script.Parent.Parent.Door door.CanCollide = false wait(3) door.CanCollide = true return end Input = "" print("Wrong Code") end script.Parent.Enter.ClickDetector.MouseClick:connect(Enter)
under this script i have this function for button
function Click0() Input = Input..0 print("0") script.Parent.B0.Decal.Texture = "http://www.roblox.com/asset/?id=2767674" wait(0.1) script.Parent.B0.Decal.Texture = "http://www.roblox.com/asset/?id=2761903" end script.Parent.B0.ClickDetector.MouseClick:connect(Click0)
I have this for B0,B1,B2 etc.. for number 1 to 9
What you can do is fire a remote event that the client listens for and when that remote event is fired open the door locally so that nobody else has access. The trick is to use a LocalScript and open the door from there. Here is an example from my past work:
-- ServerScript -- local player = players:FindFirstChild(playerName) if player then doorOpener:FireClient(player, script.Parent) -- for me script.Parent was the door model end
And LocalScript:
-- This script is by Phlegethon5778 -- -- Variables -- local replicatedStorage = game:GetService("ReplicatedStorage") local doorOpener = replicatedStorage:WaitForChild("OpenDoorEvent") -- Event -- if doorOpener then doorOpener.OnClientEvent:Connect(function(door) local doorPartList = door:GetChildren() if #doorPartList > 0 then for i,v in pairs(doorPartList) do if v:IsA("BasePart") then v.CanCollide = false v.Transparency = 1 end end end end) end
For this script to work I had to have a remote event instance in ReplicatedStorage named "OpenDoorEvent". I fired the event from the server on an event. In your case, when they enter the correct code. Then when that is accomplished just put the event listener in the client and make the function that runs when the event is fired open the door. I hope this helps and have a great day scripting!
Extra: More on remote events here, more on events here, and more on server/client relationship here.