Answered by
5 years ago Edited 5 years ago
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.
01 | local value = workspace.GreenTycoon.UserIdValue |
02 | local door = workspace.GreenTycoon.Door |
04 | door.Touched:Connect( function (hit) |
05 | local hitParent = hit.Parent |
06 | local humanoid = hitParent:FindFirstChild( "Humanoid" ) |
08 | local player = game.Players:GetPlayerFromCharacter(hitParent) |
09 | value.Value = Player.UserId |
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.
01 | local tycoon = workspace.GreenTycoon |
02 | local toggle = tycoon.Toggle |
03 | local laser = tycoon.laser -Example |
04 | local value = workspace.GreenTycoon.UserIdValue |
05 | local newValue = instance.new("BoolValue, toggle) |
08 | laser.Touched:Connect( function (hit)) |
09 | local hitParent = hit.Parent |
10 | local humanoid = hitParent:FindFirstChild( "Humanoid" ) |
12 | local player = game.Players:GetPlayerFromCharacter(hitParent) |
13 | if player.UserId ! = value.Value then |
14 | if newValue = true then |
17 | print ( "A person touched the laser, but he or she is allowed to go!" ) |
You might need to look at it a little bit to understand it, but this is how I would put it.