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

Would it be possible to make only a certain player nocollide with an object? [UNANSWERED]

Asked by
IXLKIDDO 110
9 years ago

I wanted to know if it was possible to make only a certain player nocollide with an object. For example, here's a scenario (the names are just for examples):

One player decided to join a server. Another one decided to join him. The first player will be named builderman and the second player will be called shedletsky. Builderman walks up to a door and he's able to access it, and enter it, however shedletsky cannot. Builderman cannot even possibly open the door for shedletsky because only builderman can go through it. This is due to builderman reaching a specific requirement and is nocollided with the door, but since shedletsky isn't, the door stays collidable with him.

Ending the scenario, here's what I got down so far. The "requirement" stated is being in a certain group. However, I find that while difficult, it is not impossible to keep the door open for another player (who is supposed to be restricted from entering). How would I be able to make it so that only a certain player meeting that one requirement is only nocollided with that one object, while the other one still cannot enter despite trying to hold it open (or keep it open).

script.Parent.Touched:connect(function(hit)
    if not hit.Parent:findFirstChild("Humanoid") then
        return end
    local plr = hit.Parent
    if plr:IsInGroup(GroupA) then
        script.Parent.CanCollide = false
        wait(0.3) -- My friend and I tested if it was possible to go through a door with only one of us having the requirement and it took a while, but wasn't impossible.
        script.Parent.CanCollide = true
    elseif plr:IsInGroup(GroupB) then
        script.Parent.CanCollide = false
        wait(0.3)
        script.Parent.CanCollide = true
    end 
end)
0
Hmm. One way I can think of is using localparts(via the camera or Filtering). Render the parts on the client instead of the server. NotsoPenguin 705 — 9y
1
You could just use a teleporter or make the wait a wait() and and if the player is not granted access, kill them or use Loadcharacter on them ... so on. alphawolvess 1784 — 9y
2
With filtering enabled you can do this. No collide the part from a localscript with filtering enabled on and that will only make it nocollided for that player YellowoTide 1992 — 9y
0
Another tip: Instead of two separate conditions, just connect them, since you do the same thing either way. 'if plr:IsInGroup(GroupA) or plr:IsInGroup(GroupB) then' Perci1 4988 — 9y
0
How would I do this in a localscript? IXLKIDDO 110 — 9y

1 answer

Log in to vote
0
Answered by
ZeroBits 142
9 years ago

The door seems to work fine now, but yes, someone could get in, I've modified the script to detect if a player Is NOT in the groups, and if so, it will stop that player from entering.

-- normally, I'd add a debounce, but for keeping players out, it actually hurts more than it helps

script.Parent.Touched:connect(function(hit)
    if not hit.Parent:findFirstChild("Humanoid") then
    return end
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr:IsInGroup(GroupA) then
        script.Parent.CanCollide = false
        wait(0.3)
        script.Parent.CanCollide = true
    elseif plr:IsInGroup(GroupB) then
        script.Parent.CanCollide = false
        wait(0.3)
        script.Parent.CanCollide = true
    else -- Added an else function, so if they're not in either group, the lines below fire
        hit.Anchored = true -- anchor the perpetrator, to stop him if he has really high walkspeed
        script.Parent.CanCollide = true -- door can collide
        wait(0) -- wait just long enough to keep the player from clipping through the door
        hit.Anchored = false -- unAnchor the perpetrator so he can still move
        -- if you're the perpetrator, the only thing you'll notice is a tiny bit of a jitter, and that you cannot into wall.
    end 
end)

Ad

Answer this question