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

This script is suppose to kick out every player who is not suppose to be there, can anyone help?

Asked by
NSMascot 113
5 years ago
Edited by theking48989987 5 years ago

This script is inside an invisible block, that has cancollide turned off. It is apart of a housing system btw. all locations are correct (iv'e checked),

script.Parent.Touched:Connect(function(hit)
local children = game.Players:WaitForChild(script.Parent.Parent.Info.OwnersName.Value):WaitForChild("PlayerSettings").HouseAccess:GetChildren()

    for i = 1, #children do
    if children[i].Name ~= hit.Parent.Name then
    hit.Parent.HumanoidRootPart.CFrame = CFrame.new(152.74, 2.925, -205.96)
        end
    end
end)

as you can see the children are values in a folder, the values are called the players names, it is suppose to go through the for loop and if your player name is not one of the values Name (.Value doesn't work for some reason), then it tp's you outside of the invisible block.

What it actually does is tp everyone out of the invisible block, yes my player is added to the folder where the values are contained


EXTRA INFO PlayerSettings = a folder which gets cloned into the player (Game.Players), when the player joins the game

HouseAccess = folder inside PlayerSettings were all the players names that are allowed into the invisible block are stored, the owners name is automatically put into here.

ty NSMascot

2 answers

Log in to vote
1
Answered by 5 years ago

did you try using Region3 instead? It's much more suitable for your situation.

And as for your question, I think I am a bit confused but let me try to help:

script.Parent.Touched:Connect(function(hit)
local children = game.Players:WaitForChild(script.Parent.Parent.Info.OwnersName.Value):WaitForChild("PlayerSettings").HouseAccess:GetChildren()
    for index,value in pairs(children) do
    if value.Name == hit.Parent.Name then
        return
        end
    end
    hit.Parent.HumanoidRootPart.CFrame = CFrame.new(152.74, 2.925, -205.96)
end)

Now it goes through all the children and if one of them is the player who touched it then it returns (breaks) and does nothing at all but if not any of the children is the player who touched it then it kicks them

Ad
Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago

The touch event is pretty wonky for things like this. If you're inside a brick, sometimes it'll detect you as touching, sometimes it'll detect you as not in there.

You're not going to be able to do this with touched. Try something like region3 or part:getTouchingParts().

Answer this question