Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[ANSWERED] How would i make my ban script when i test a game work?

Hello, i was making a ban script to ban anyone that isnt allowed to test if the script is not disabled. However it doesnt work, any explanations or answers why?

local reason = ("Game is closed for testing.")
local allowed = ("ChronoFantastic")
while true do
	wait(.1)
	for i,v in pairs(game.Players:GetChildren()) do
		if v ~= allowed then
			v:Kick(reason)
		elseif v == allowed then
			end
	end
	end

9 comments

0

I think it's because on line 6 where it says v you need to say v.Name. Also, you would need to do allowed[1].

0

^ Thanks ill try that. Oh and ill post the output too. I use script analysis too to help

0

IT WORKED! Thank you for your help :)

0

You're very welcome, also I don't think you have to do, "allowed[1]," because I just realized the allowed variable wasn't a table.

0

Can you friend me on roblox though?

0

Request sent.

0

Done.

0

In lines 1-2, you wrapped your string in brackets. Brackets are math exclusive. Remove them.

0

^ The questions answered already. Sorry.

1 answer

✓ Accepted answer

You're comparing a userdata and a string. You'd have to do v.Name like rollercoaster125634 said.

Here's some code that should work.

local Players = game:GetService("Players")

local Reason = "Game is closed for testing."
local Allowed = {"ChronoFantastic"}

local function IsAllowed(Name)
	for I, V in next, Allowed do
		if Name == V then
			return true
		end
	end
	return false
end

local function AddPlayer(Plr)
	if not IsAllowed(Plr.Name) then
		Plr:Kick(Reason)
	end
end

for I, V in ipairs(Players:GetPlayers()) do
	AddPlayer(V)
end

Players.PlayerAdded:Connect(AddPlayer)

p.s, use UserIds to identify players as they may change their usernames.

2 comments

0

Works, great, exept rollercoaster helped alot too. Both of you really helped me.

0

No problem. :')

This discussion is preserved as it was. New answers, comments, and votes are closed.