Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can you help me with this? I am making an owner only door and am stuck with the code

Im making a tycoon and got stuck on the owner only door. Can you help?

local owner = script.Parent.Parent.Parent.Owner
local door = script.Parent

function onTouched(hit)
	local character = hit.Parent
	local plr = game.Players:GetPlayerFromCharacter(character)
	if plr and plr.Name ~= owner.Value then
		character:BreakJoints()
	end
end

door.Touched:connect(onTouched)

1 answer

You seem to only make the function that kills the player if he's not the owner. Let's make then the other function:

local owner = script.Parent.Parent.Parent.Owner
local door = script.Parent

function onTouched(hit)
	local character = hit.Parent
	local plr = game.Players:GetPlayerFromCharacter(character)
	if plr and plr.Name ~= owner.Value then
		character:BreakJoints()
	elseif plr and plr.Name == owner.Value then
		script.Parent.CanCollide = false
		script.Parent.Transparency = 0.5
		wait(1)
		script.Parent.CanCollide = true
		script.Parent.Transparency = 0
	end
end

door.Touched:connect(onTouched)

As you see, I added an elseif statement which checks if it's the owner. If it is, then the door turns uncollidable which means he can go through. I also turn it transparent to not seem he's crossing a solid wall. Hope this helped!

This discussion is preserved as it was. New answers, comments, and votes are closed.