I cant figure out how to make an owner door for a house. Im trying to make a door for a house like For Example, Pacifco 2 does. Im making a** RP game and im stuck at the door script. Hope you can help me. :D
Alright, this is how to make an owner only door. If anyone else comes, the door will kill them, and this can be toggled.
Sorry if there are some errors with the code, I'm not too good at it. Also note that the pathway for the variables are just examples (noted by "example")
First, let's put a value for the code to identify who should be allowed. This can be done at the start when a player claims a tycoon.
local value= workspace.GreenTycoon.UserIdValue --Example local door= workspace.GreenTycoon.Door --Example door.Touched:Connect(function(hit) local hitParent= hit.Parent local humanoid= hitParent:FindFirstChild("Humanoid") if humanoid then local player= game.Players:GetPlayerFromCharacter(hitParent) value.Value= Player.UserId --The rest of the code you're going to put when a player claims it. end end
Next, when the owner only door is purchased, with the lasers and switch, let's add this code to let only the owner throught based on the switch.
local tycoon= workspace.GreenTycoon --Example local toggle= tycoon.Toggle --Example --Example local laser= tycoon.laser -Example --Example local value= workspace.GreenTycoon.UserIdValue --Example local newValue= instance.new("BoolValue, toggle) --Example newValue.Value= true laser.Touched:Connect(function(hit)) local hitParent= hit.Parent local humanoid= hitParent:FindFirstChild("Humanoid") if humanoid then local player= game.Players:GetPlayerFromCharacter(hitParent) if player.UserId != value.Value then if newValue= true then humanoid.Health= 0 else print("A person touched the laser, but he or she is allowed to go!") end end end end
You might need to look at it a little bit to understand it, but this is how I would put it.