How do I fix this line of code ruining my script?

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

The first argument to :FireClient is the player to fire to. Reverse your arguments.

2 Likes

so

game.ReplicatedStorage.Warning:FireServer(Reason, PlayerToWarn)

?

Edit: when I do that it gives me an error that it can only be done via client.

If you are sending this to the server from your client as an admin command or such then yes.

If you are sending it from the server to a specific client then you need to do

:FireClient(PlayerToWarn, Reason)
1 Like

To send to the server, simply do event:FireServer(arguments). To send to the client, do: event:FireClient(playerToFire, arguments)

1 Like

Okay thanks @DreamWakeStudios and @lifacy, I also get this error after I fixed that.

18:28:40.173 - Workspace.NotAid_n.Head.WarningGUI.ClientSideWarning:5: attempt to index nil with ‘Character’

18:28:40.175 - Stack Begin

18:28:40.177 - Script ‘Workspace.NotAid_n.Head.WarningGUI.ClientSideWarning’, Line 5

18:28:40.177 - Stack End

on this line:

local WarningGUI = PlayerToWarn.Character.Head.WarningGUI

any idea how I fix that?

local char = PlayerToWarn.Character or PlayerToWarn.CharacterAdded:Wait()

Try that instead? That may work.

2 Likes

still got this
18:33:34.146 - Workspace.NotAid_n.Head.WarningGUI.ClientSideWarning:6: attempt to index nil with ‘Character’

18:33:34.149 - Stack Begin

18:33:34.150 - Script ‘Workspace.NotAid_n.Head.WarningGUI.ClientSideWarning’, Line 6

18:33:34.151 - Stack End

18:33:39.329 - Disconnect from ::ffff:127.0.0.1|60488
Edit; NVM put wrong thing!

even when i did that like you said it didn’t fix it.

1 Like