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

Why isn't this owner only door (door that only lets the owner of the game go through it) working?

Asked by
EpicLilC 150
7 years ago

So bassically I was trying to make it so that when I (which is represented by my UserId) touch the part that this script is in, the part goes transparent, and I can walk through it.

script.parent.Touched:connect(function(hit)
    if hit.UserId == "34310670" then
        print 'Hello, EpicLilC'
        script.parent.Transparency = .5
        script.parent.CanCollide = false
    end
end)

How come this script doesn't work?

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

There are a few problems here.

First off, the "hit" is a BasePart, not a Player. That part could be the handle of an accessory, the Right leg, or anything. You must first check if it has a humanoid, then check if it is a player.

script.parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChildOfClass("Humanoid") then -- Checks if it has a humanoid
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent) -- Gets the player associated with the character
    if plr then -- Make sures it is actually there
        if plr.UserId == 34310670 then -- Makes sure it has the correct userid
                print 'Hello, EpicLilC'
                script.Parent.Transparency = .5
                script.Parents.CanCollide = false
        end
    end
    end
end)

Second, UserId is an int, not a string, as you put in the code. Lastly, it is Parent, not parent.

Hope this helps!

Ad

Answer this question