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

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

Asked by 7 years ago

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'

01local Blockers = {'hello'}
02 
03game:GetService("Players").PlayerAdded:connect(function(newPlayer)
04    newPlayer.Chatted:Connect(function(newMessage)
05        for index, value in pairs(Blockers) do
06            if newMessage == value then
07                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.")
08            end
09        end
10    end)
11end)
2
Where is the location of this script? PyccknnXakep 1225 — 7y
0
Change it to local script HackerLau_Gaming -5 — 7y

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

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

01local Blockers = {'hello'}
02local 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."
03 
04game.Players.PlayerAdded:Connect(function(newPlayer) --Use "Connect"!
05    newPlayer.Chatted:Connect(function(newMessage)
06        for i, v in pairs(Blockers) do
07            --string.lower() comparison so cases aren't an issue
08            if newMessage:lower() == v:lower() then
09                newPlayer:Kick(msg) --Use "newPlayer" parameter!
10            end
11        end
12    end)
13end)

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

0
Thanks I was looking everywhere for a script that worked. Thankyou! Goldenkings11 -11 — 7y
Ad

Answer this question