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

Why is this script working in studio mode, but not in player mode?

I tried making it a LocalScript and it is currently a script. What is wrong with this code blocker script. Why whenever you say the code it doesn't kick you in player mode. It works in studio mode, but in players mode it doesn't work... why?! Please help me quickly because my big game 'Code Hunters II is opening this Friday 7/21/17'

local Blockers = {'hello'}

game:GetService("Players").PlayerAdded:connect(function(newPlayer)
    newPlayer.Chatted:Connect(function(newMessage)
        for index, value in pairs(Blockers) do
            if newMessage == value then
                game.Players.LocalPlayer:Kick("Sorry, you have been kicked from the server. Please do NOT spoil the codes or ruin the other robloxians experience. You are not banned so you could rejoin.")
            end
        end
    end)
end)

2 comments

2

Where is the location of this script?

0

Change it to local script

1 answer

✓ Accepted answer

You cannot index LocalPlayer on the server - just use your newPlayer parameter!

local Blockers = {'hello'}
local msg = "Sorry, you have been kicked from the server. Please do NOT spoil the codes or ruin the other robloxians experience. You are not banned so you could rejoin."

game.Players.PlayerAdded:Connect(function(newPlayer) --Use "Connect"!
	newPlayer.Chatted:Connect(function(newMessage)
		for i, v in pairs(Blockers) do
			--string.lower() comparison so cases aren't an issue
			if newMessage:lower() == v:lower() then
				newPlayer:Kick(msg) --Use "newPlayer" parameter!
			end
		end
	end)
end)

Make sure this is a Script object running on the server - e.g. in Workspace or ServerScriptStorage(preferably the latter).

1 comment

0

Thanks I was looking everywhere for a script that worked. Thankyou!

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