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

How do you destroy a table using scripts?

Asked by
Fla_res 13
4 years ago

So I have tried to create a block that kicks players, but not the people in the written string:~~~~~~~~~~~~~~~~~

("Fla_res,gloveshun") ~



 And I have written a code that kicks people that hit the block.
It has been succesfull, due to the output BUT I am trying to destroy the table so that the people in the string do not get kicked.
If i've written something wrong please tell me since i am a new scripter. 
here is the code: ~~~~~~~~~~~~~~~~~

script.Parent.Touched:connect(function(onTouched) game.Players:FindFirstChild("Humanoid"):kick("You have been kicked for not listening to what I have said.") if localPlayer ("Fla_res,gloveshun")

after local player , I got stuck and confused

0
oops kinda messed up the codes Fla_res 13 — 4y
0
I will answer this when I return home. RyanTheLion911 195 — 4y

2 answers

Log in to vote
0
Answered by
Psudar 882 Moderation Voter
4 years ago

So im guessing you're trying to make it so that you can check whos in the table, and if they're not in the table, you want to kick them. Thats pretty straightforward. Here's how I would do it:

--Psudar
--Sep 1 2019
--Server Script (Parented to part)

--//Services

local Players = game:GetService("Players")

--//Instances

local Part = script.Parent
--our table of players allowed
local WhiteList = {"Psudar", "Rorarius", "ii_Pekk"}

--//Functions

--this finds the player in a table using name
local function AllowedPlayer(tbl, playername)
    for i, v in pairs (tbl) do
        if v == playername then
            return true
        end
    end
end

local function onTouched(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        --we can get the player from their character like this:
        local PlayerWhoTouched = Players:GetPlayerFromCharacter(hit.Parent)
        --we use our function to check if they're whitelisted
        if not AllowedPlayer(WhiteList, PlayerWhoTouched.Name) then
            --if they arent, kick them
            PlayerWhoTouched:Kick("You're not allowed")
        end
    end
end

--//Connections
--connect the touched function when part is touched
Part.Touched:Connect(onTouched))

Basically all we do here is run a function when the part is touched. We have an if-statement that determines if the player is allowed. If they're not, we simply kick them. The function that determines that literally just looks inside the table for the player's name, if its not, we kick them.Simple as that! :D

1
Thanks dude! Fla_res 13 — 4y
0
Np mate. Psudar 882 — 4y
Ad
Log in to vote
0
Answered by
gloveshun 119
4 years ago
Edited 4 years ago

bro, what is this? can i help ya? My whitelist script:

local WhiteList = {"gloveshun", "Fla_res"; "Player...?"}
game.Players.PlayerAdded:Connect(function(player)
for i, v in pairs(WhiteList) do
    if not player.Name == WhiteList[v] then
        player:Kick("You are no allowed here!")
    else
    print(player.Name.." Passed!")
    end
end
end)

Answer this question