One line of code keeps ruining my warning system script. How do I fix this?
The Line of code:
game.ReplicatedStorage.Warning:FireClient(Reason, PlayerToWarn)
The whole script:
local GroupId = 6741421
local MinimumRankToUseCommand = 9
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local WarningGUI = script.WarningGUI:Clone()
WarningGUI.Parent = Character.Head
end)
local TextService = game:GetService("TextService") -- TextService variable
Player.Chatted:Connect(function(Message)
local SplitMessage = Message:split(" ")
if SplitMessage[1] == "!warn" and Player:GetRankInGroup(GroupId) >= MinimumRankToUseCommand then
local NameOfPlayerToWarn = SplitMessage[2]
local PlayerToWarn = game.Players:FindFirstChild(NameOfPlayerToWarn)
local Reason = Message:split(NameOfPlayerToWarn)[2]
local WarningGUI = PlayerToWarn.Character.Head.WarningGUI
local CurrentWarnings = WarningGUI.Warnings
local playerName = PlayerToWarn.Name
game.ReplicatedStorage.FilterWarn.OnServerInvoke = (function(playerName, Reason) -- server receives invoke
local filteredTextResult = TextService:FilterStringAsync(Reason, Player.UserId) -- filters string
return filteredTextResult:GetNonChatStringForBroadcastAsync() -- returns filtered string to the client
end)
game.ReplicatedStorage.Warning:FireClient(Reason, PlayerToWarn)
end
end)
end)
The Error:
18:19:32.229 - Unable to cast value to Object
18:19:32.231 - Stack Begin
18:19:32.235 - Script âWorkspace.WarnCommandâ, Line 29
18:19:32.235 - Stack End