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

How can I fix a whitelisting script when rejoining the game makes it not work?

Asked by 4 years ago

It is kind of difficult to write it in a sentence for people to understand. Recently I have been trying to make a script in which anyone who isn't in a designed whitelist will have a NPC target them down, which will cause them to get kicked on touch. It worked, but when they rejoin or another person joins. The NPC does not spawn in. Sort of need some help in regards to this.

Here is the script I had trouble on

--Whitelist script by fridayboycool : Modified by XenilMatrix [HUGE CREDITS TO OWNER]
local whitelisted = {
    ["XenilMatrix"] = true;
    [""] = true;
    ["Player1"] = true;
}

local player = script.Parent.Parent
local teams = game.Teams

--------------------------------------------------------------------------------------------------------------------

while true do
    wait(0.01)
    if whitelisted[player.Name] then 
    else -- 2020/3/31 Got it working but failure to repeat again when another invalid person joins the game, but they are not listed.
        while true do
            wait(0.001)
        if #teams.Players:GetPlayers() > 0 then
            local Object = game.ReplicatedStorage["NPC"]:Clone()
            Object.Parent = game.Workspace
            Object.Position = Vector3.new()
            Object:MoveTo(Vector3.new(0,0,0))
            wait(0.001)
            end
        end
    end
end

2 answers

Log in to vote
0
Answered by
Infocus 144
4 years ago
Edited 4 years ago
--Whitelist script by fridayboycool : Modified by XenilMatrix [HUGE CREDITS TO OWNER]

local whitelisted = {
    ["XenilMatrix"] = true;
    [""] = true;
    ["Player1"] = true;
}

local player = script.Parent.Parent
local teams = game.Teams

game.Players.PlayerAdded:connect(function(plyr)
    repeat wait() until plyr.Character
    if not whitelisted[plyr.Name] then
        local object = game.ReplicatedStorage["NPC"]:Clone()
        object.Parent= game.Workspace
        object.Position = Vector3.new()
        while wait(.03) do
            if not whitelisted[plyr.Name] ~= nil then
                object:MoveTo(Vector3.new(0, 0, 0))
            else
break
            end
        end
    end
end)
0
In this script, I utilized the player added event, which is more efficient than constantly checking if there are more than 0 players. I check if the player that joined isn't in the whitelist, if that person isn't, then I copy the npc. I also made it so if that player isn't there anymore, then the npc is removed. NOTE: IF THERE ARE TWO OR MORE NON WHITELISTED PPL THIS MIGHT BREAK. Infocus 144 — 4y
0
Is there anyway to fix that problem, in regards to the script breaking when there are more unlisted ppl? XenilMatrix 2 — 4y
0
let me edit Infocus 144 — 4y
0
You have to edit lines 17 and 20 in order for your NPC to move and be positioned Infocus 144 — 4y
0
I acknowledge that, I already got a NPC already made. It does move and I believe it is positioned. XenilMatrix 2 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

I'm confused as to why you don't do this on the server. I don't understand any of your bot stuff so I'll just have you do that manually

Disclaimer: Put this in a script on the server

local whitelisted = {
        ["XenilMatrix"] = true;
        [""] = true;
            ["Player1"] = true;
}
game.Players.PlayerAdded:Connect(function(player)
    local character = player.Character or player.CharacterAdded:Wait()
    local touched = false
    if not whitelisted[player.Name] then
        while true do
            wait()
            ##Bot following player here

        end
    end
end)

I should probably break the loop as soon as the player gets kicked but I can't be bothered to test if it would work.

Make sure to tell me if this helps

0
mb didnt see that someone already replied. you can ignore avengerstar 74 — 4y
0
Two great minds think alike though Infocus 144 — 4y
0
haha i guess so avengerstar 74 — 4y

Answer this question