Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make my Owner Only Door work ?

Asked by 10 years ago

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!

0
Make sure that 'Owner' is a StringValue, other than that.. your script looks fine. Goulstem 8144 — 10y

1 answer

Log in to vote
1
Answered by
Tkdriverx 514 Moderation Voter
10 years ago

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)
0
They pass through no matter what even if they arent the Owner TixyScripter 115 — 10y
0
I edited it. It's possible the script couldn't find the "Owner" value, so I changed it to wait for it. Tkdriverx 514 — 10y
0
It works just fine on my end. Tkdriverx 514 — 10y
0
trying the new one! TixyScripter 115 — 10y
View all comments (4 more)
0
I might consider using his tycoon kit when I'm feeling lazy. I've never seen how it works before. xD Tkdriverx 514 — 10y
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 TixyScripter 115 — 10y
0
I just put the part directly into the "Purchases" model. Tkdriverx 514 — 10y
0
can you follow me to my place really quick so we can talk? TixyScripter 115 — 10y
Ad

Answer this question