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

How can I make my Owner Only Door work ?

So I am using Berezaa's Tycoon kit and I have been making a owner only door and I don't know what is wrong with the script. The script has 3 Parents OwnerOnlyDoor, then Purchases, and then there is Bright Blue where there is a Owner Value. That means there is 3 Parents so I edited it to three parents and also the Value is called Owner not OwnerName so I changed that to Owner and it still wont work. It may be because the type of value the Owner is a Object Value idk. If you can help me out please!!! My script:

function onTouched(hit)
local owner = script.Parent.Parent.Parent.Owner
local h = hit.Parent:findFirstChild("Humanoid")
	if (h ~= nil) then
		if h.Parent.Name == owner.Value then
			script.Parent.CanCollide = false
			wait(2)
			script.Parent.CanCollide = true
			else h.Health = 0
		end
	end
end
script.Parent.Touched:connect(onTouched)

THANKS!

1 comment

0

Make sure that 'Owner' is a StringValue, other than that.. your script looks fine.

1 answer

✓ Accepted answer

Your code would work, if it were a StringValue. But, "Owner" is an ObjectValue, not a StringValue.

The way his tycoon kit is coded, it saves the actual player to the Owner value. So you need to locate the player.

In order to do this, inside the touched function, instead of searching for the humanoid, search for the player from the character.

TIP Don't set the CanCollide by the script. Just have it set to false in the first place. If it's the owner, they'll just pass right through and the code will do nothing. Otherwise, it'll kill them. This is what I did in my code here:

local owner = script.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!
			human.Health = 0
		end
	end
end)

8 comments

0

They pass through no matter what even if they arent the Owner

0

I edited it. It's possible the script couldn't find the "Owner" value, so I changed it to wait for it.

0

It works just fine on my end.

0

trying the new one!

0

I might consider using his tycoon kit when I'm feeling lazy. I've never seen how it works before. xD

0

Can you make a model of your Owner Only Door cause it may be mine or where I put it because i keep jsut walking through it

0

I just put the part directly into the "Purchases" model.

0

can you follow me to my place really quick so we can talk?

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