In studio my chat commands work, they do what I've coded them to do. However, whenever I try in roblox Player if never works. Why is this the case?

local CommandsTTable = require(game.ReplicatedStorage.ListOfCommands)
local PlayersAllowedToUseCommands = require(game.ReplicatedStorage.PlayersPermittedToUseCommand)
local PlayersService = game:GetService("Players")
local MaxAmountOfWarns = 3

PlayersService.PlayerAdded:Connect(function(Player)
	local Warns = Instance.new("NumberValue")
	Warns.Parent = Player
	Warns.Value = 0
	Warns.Name = "Warns"
	local function Check()
		for i, playerAllowed in pairs(PlayersAllowedToUseCommands) do
			if Player.Name == playerAllowed then
				return true
			else
				return false
			end
		end
	end
	Player.Chatted:Connect(function(WhatTheySaid)
		local SplitMessage = WhatTheySaid:split(" ")
		if SplitMessage[1] == CommandsTTable[1] then --KickCommand
			Check()
			if Check() then
				local NameOfTargetedPlayer  = SplitMessage[2]
				local ActualTargetedPlayer = PlayersService:FindFirstChild(NameOfTargetedPlayer)
				local Reason = WhatTheySaid:split(NameOfTargetedPlayer)[2]
				ActualTargetedPlayer:Kick(Reason)
			end
		elseif Check() and SplitMessage[1] == CommandsTTable[4] then
			local NameOfPlayer = SplitMessage[2]
			local AccPlayer = PlayersService:FindFirstChild(NameOfPlayer)
			local WarnsInPlayer = AccPlayer:WaitForChild("Warns")
			local Reason = WhatTheySaid:split(NameOfPlayer)[2]
			Warns.Value += 1
			print("You Have Been Warned For ".. Reason)
			if Warns.Value == MaxAmountOfWarns then
				AccPlayer:Kick("Reached Max Amount Of Warns")  --Change this to what you want
			end
		elseif Check() and SplitMessage[1]== CommandsTTable[3] then
			local NamePlr = SplitMessage[2]
			local CharacterOfPlayer = workspace:FindFirstChild(NamePlr)
			local HumanoidOfChar = CharacterOfPlayer:WaitForChild("Humanoid")
			HumanoidOfCharHealth = 0
			if HumanoidOfChar.Health == 0 then
				print("Killed Player")
			end
		end
	end)
end)

	

3 comments

0

I have my script in serverscriptservice and my modules in repstorage btw

0

Make sure you have published your game,it happens that i save instead of it

0

Ye ive published it, but ill republish it anyway