New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
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 11 days ago
Edited by theking48989987 11 days 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 11 days 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 1796 Moderation Voter
11 days 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