Hello, I am having problems with my Owner Only Door script. I have buttons for it that Change the color of the Door, One is open which changes it to Lime green (open for others to get in) and the other is close which makes it red (not open for others to get in) I have this script to make it work with the colors so if someone passes through it when its red they die but if green they live.
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then if game.Players:GetPlayerFromCharacter(hit.Parent) then if script.Parent.BrickColor == BrickColor.new("Lime green") then print("passed safely") elseif script.Parent.BrickColor = BrickColor.new("Really red") then if player ~= Owner then hit.Parent:BreakJoints() end print("you shall not pass") end end end end)
I wanted to edit this script so that if you are the owner of the tycoon you can pass through the door even if it is open or closed and this is what I ended up with.
local owner = script.Parent.Parent.Parent.Parent:WaitForChild("Owner") script.Parent.Touched:connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- If it's not a player's character, it won't break. if player then -- Checks if a player exists from that character. -- Now look for the humanoid, now we know it's there because we know for sure it's a player character. local human = hit.Parent:findFirstChild("Humanoid") -- It's there for sure. -- Might as well double check. if human and player ~= owner.Value then -- If it's not the owner, kill them! else script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then if game.Players:GetPlayerFromCharacter(hit.Parent) then if script.Parent.BrickColor == BrickColor.new("Lime green") then print("passed safely") elseif script.Parent.BrickColor = BrickColor.new("Really red") then if player ~= Owner then hit.Parent:BreakJoints() end print("you shall not pass") end end end end)
The problem is that when I use this others can also pass through whether Red or green even if there not the tycoon owner. If you edit it please make sure the Owner of the tycoon can still pass through no matter what. Also the Owner value is changed as a person joins the tycoon. Please help! All answers/feedback is appreciated!
Assuming you have an owner value that says who's the owner then
local owner = script.Parent:WaitForChild("Owner") script.Parent.Touched:connect(function(hit) if hit.Parent.Name == owner.Value.Name then --Assuming that this is an object value print("youre da boss") else print("check check your neck") if script.Parent.BrickColor = BrickColor.new("Really red") then print("you shall not pass") --do your stuff you can explode them elseif script.Parent.BrickColor = BrickColor.new("Lime green") then print("my boss let you enter") else print("boss im confused") end end end)
I have a question about it. Is there multiple owners or just one? Because, if there is multiple owners I can understand the owner part, however, if it is only you considered as an owner, then just change it or add in, something like: (((If red color here then kill script elseif player.name == "your name"))). Something like that could be easy .-.
elseif script.Parent.BrickColor = BrickColor.new("Really red") then
You forgot the other = sign. Line 16 rewrite it to:
elseif script.Parent.BrickColor == BrickColor.new("Really red") then
Also, I believe you should put the Owner variable as a table.