I'm trying to fix my owner only doors issue that kills the regular player(not the owner of tycoon) even though the door is opened and everyone can get in. My code:
local Players = game:GetService("Players") local enabled = true local lasers = script.Parent.Lasers local button = script.Parent.Button local ownerValue = script.Parent.Parent.Parent.Values.OwnerValue lasers.CanCollide = false button.ClickDetector.MouseClick:Connect(function(playerWhoClicked) if ownerValue.Value == playerWhoClicked then if enabled == true then enabled = false lasers.Transparency = 0.8 else enabled = true lasers.Transparency = 0 end end end) -- The lasers(thing im tryna fix) lasers.Touched:Connect(function(hit) if hit.Parent:FindFirstChildOfClass("Humanoid") then local player = Players:GetPlayerFromCharacter(hit.Parent) if ownerValue.Value ~= player then hit.Parent:FindFirstChild("Humanoid").Health = 0 end end end)
I think I have saw the problem. When you are running the laser function, you end up just checking if: - There is a humanoid - If it is not the owner. However, you also need to check to see if the lasers are enabled. You have already created a variable for this for the button, but not used it to see if the lasers are enabled or not so simply, you can just add that to the if statement.
lasers.Touched:Connect(function(hit) if hit.Parent:FindFirstChildOfClass("Humanoid") and enabled then local player = Players:GetPlayerFromCharacter(hit.Parent) if ownerValue.Value ~= player then hit.Parent:FindFirstChild("Humanoid").Health = 0 end end end)
Now the code will simply check if there is a humanoid AND if the enabled variable is true.