Help with Server script

I am trying to make a clothing script that make the player wear the clothes they were previously wearing before they died and It does not work. I don’t know what to do. I did It with a local script before but I want it to use a sever script so that it is more secure. I got an error saying “Argument 1 missing or nil”. (I have more than 1 shirt in CheckAndFire function. I didn’t want people reading a long script )

Local Script(Old)

local player =  game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local shirt = player:WaitForChild("aye"):WaitForChild("shirt") 

local function checkAndFire()
	if shirt.Value == "whitesleeve" then 
		ReplicatedStorage.Events.ShirtEvent5:FireServer() 
	end
end
checkAndFire() --Run when player joins
player.CharacterAdded:Connect(checkAndFire)

Local Script

--Used to start the event in the serverscript below 
local player =  game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
player.CharacterAdded:Connect(function()
	ReplicatedStorage.Events.CheckEvent:FireServer()
end)

Server Script(What I tried)

game.ReplicatedStorage.Events.ShirtEvent5.OnServerEvent:Connect(function(plr)
	local char = plr.Character
	local q = BrickColor.new("White")
	local Tors = char["UpperTorso"]
    Tors.BrickColor = q
end)
game.ReplicatedStorage.Events.CheckEvent.OnServerEvent:Connect(function(plr)
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	local shirt = plr:WaitForChild("aye"):WaitForChild("shirt") 
	local function checkAndFire()
		if shirt.Value == "whitesleeve" then 
			ReplicatedStorage.Events.ShirtEvent5:FireClient() 
		end
	end
	checkAndFire() 
end)
1 Like

FireClient requires a player argument to pass, and can only be used to receive on the client using OnClientEvent Idk why you have multiple functions checking for those, you could just do this in 1 function alone:

game.ReplicatedStorage.Events.CheckEvent.OnServerEvent:Connect(function(plr)
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local char = plr.Character
    local q = BrickColor.new("White")
	local shirt = plr:WaitForChild("aye"):WaitForChild("shirt") 
    local Tors = char:WaitForChild("UpperTorso", 3)

	if shirt.Value == "whitesleeve" then
        Tors.BrickColor = q 
    end
end)
1 Like

I have more than 1 shirt in the checkAndFire function and the shirt events that I have are more complicated. I didn’t want people reading a long script. I probably should have said that.

Yeah you probably should’ve
Just don’t use the FireClient function, that’ll only work from transferring server-client sided keep it nice and simple

game.ReplicatedStorage.Events.CheckEvent.OnServerEvent:Connect(function(plr)
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local char = plr.Character
    local q = BrickColor.new("White")
	local shirt = plr:WaitForChild("aye"):WaitForChild("shirt") 
    local Tors = char:WaitForChild("UpperTorso", 3)

	local function checkAndFire()
		if shirt.Value == "whitesleeve" then 
		    Tors.BrickColor = q
		end
	end
	checkAndFire() 
end)