How to find/send the player's character via Remote Event

Current Script:

local Button = script.Parent
local Outfit = script.Parent.Name

Button.MouseButton1Down:Connect(function(player)
	
	game.ReplicatedStorage.Uniforms.SS:FireServer(Outfit)
	
end)

GOAL

To be able to send the player’s character via a Remote Event, that way I can make the following script work for a “locker system” for accessories:

local FloodCheck = require(game.ServerScriptService.RemoteFloodCheck)


local Formals = {

	[5] = {hat = game.ServerStorage.Accessories.Accessory};
	[10] = {hat = game.ServerStorage.Accessories.Accessory};
	[15] = {hat = game.ServerStorage.Accessories.Accessory};
	[20] = {hat = game.ServerStorage.Accessories.Accessory};
	[25] = {hat = game.ServerStorage.Accessories.Accessory};
	[30] = {hat = game.ServerStorage.Accessories.Accessory};
	[35] = {hat = game.ServerStorage.Accessories.Accessory};
	[37] = {hat = game.ServerStorage.Accessories.Accessory};
	[40] = {hat = game.ServerStorage.Accessories.Accessory};
	[42] = {hat = game.ServerStorage.Accessories.Accessory};
	[45] = {hat = game.ServerStorage.Accessories.Accessory};
	[50] = {hat = game.ServerStorage.Accessories.Accessory};
	[55] = {hat = game.ServerStorage.Accessories.Accessory};
	[60] = {hat = game.ServerStorage.Accessories.Accessory};
	[61] = {hat = game.ServerStorage.Accessories.Accessory};
	[62] = {hat = game.ServerStorage.Accessories.Accessory};
	[63] = {hat = game.ServerStorage.Accessories.Accessory};
	[66] = {hat = game.ServerStorage.Accessories.Accessory};
	[67] = {hat = game.ServerStorage.Accessories.Accessory};
	[68] = {hat = game.ServerStorage.Accessories.Accessory};
	[70] = {hat = game.ServerStorage.Accessories.Accessory};
	[255] = {hat = game.ServerStorage.Accessories.Accessory};
};

local accessremote = game.ReplicatedStorage.Accessories.access

game.ReplicatedStorage.Uniforms.Formals.OnServerEvent:Connect(function(plr)
	if FloodCheck:Check(plr, accessremote, 0.08333) then


		local formalrank = plr.Groups["[CUSA] United States MiIitary"].Rank.Value
		local info = Formals[formalrank]
		print (info)
		if info then
	
					local g = info.hat
					g.Parent = hit.Parent
					local C = g:GetChildren()
					for i=1, #C do
						if C[i].className == "Part" or C[i].className == "UnionOperation" or C[i].className == "MeshPart" or C[i].className == "WedgePart" then
							local W = Instance.new("Weld")
							W.Part0 = g.Middle
							W.Part1 = C[i]
							local CJ = CFrame.new(g.Middle.Position)
							local C0 = g.Middle.CFrame:inverse()*CJ
							local C1 = C[i].CFrame:inverse()*CJ
							W.C0 = C0
							W.C1 = C1
							W.Parent = g.Middle
							g.Middle.Transparency = 1
						end
						local Y = Instance.new("Weld")
						Y.Part0 = hit.Parent.Head
						Y.Part1 = g.Middle
						Y.C0 = CFrame.new(0, 0, 0)
						Y.Parent = Y.Part0
					end

					local h = g:GetChildren()
					for i = 1, # h do
						h[i].Anchored = false
						h[i].CanCollide = false
					end

				end


	end
end)

When receiving the event on the server do:

local character = player.Character or player.CharacterAdded:Wait() 
game.ReplicatedStorage.Uniforms.Formals.OnServerEvent:Connect(function(plr)
    local plrCharcter = plr.Character or plr.CharacterAdded:Wait()

	if FloodCheck:Check(plr, accessremote, 0.08333) then

You cannot send instances over remote events. I recommend using one of these methods:

I recommend using the first one if you just want the accessory information and using the second one if you want the accessories to be created.

You can send instances, as long as they are replicated in the server and the client

2 Likes

@HugeCoolboy2007 's method worked great; this is the second post you’ve helped me on today. Well done haha.

Further info:

local FloodCheck = require(game.ServerScriptService.RemoteFloodCheck)

local function accessoryspawn(plr,g)
	local char = plr.Character or plr.CharacterAdded:Wait() 

		g.Parent = char.Parent
		local C = g:GetChildren()
		for i=1, #C do
			if C[i].className == "Part" or C[i].className == "UnionOperation" or C[i].className == "MeshPart" or C[i].className == "WedgePart" then
				local W = Instance.new("Weld")
				W.Part0 = g.Middle
				W.Part1 = C[i]
				local CJ = CFrame.new(g.Middle.Position)
				local C0 = g.Middle.CFrame:inverse()*CJ
				local C1 = C[i].CFrame:inverse()*CJ
				W.C0 = C0
				W.C1 = C1
				W.Parent = g.Middle
				g.Middle.Transparency = 1
			end
			local Y = Instance.new("Weld")
			Y.Part0 = char.Head
			Y.Part1 = g.Middle
			Y.C0 = CFrame.new(0, 0, 0)
			Y.Parent = Y.Part0
		end

		local h = g:GetChildren()
		for i = 1, # h do
			h[i].Anchored = false
			h[i].CanCollide = false
		end
	end



local Formals = {

	[5] = {hat = game.ServerStorage.USMPatrol.E2};
	[10] = {hat = game.ServerStorage.USMPatrol.E2};
	[15] = {hat = game.ServerStorage.USMPatrol.E2};
	[20] = {hat = game.ServerStorage.USMPatrol.E2};
	[25] = {hat = game.ServerStorage.USMPatrol.E2};
	[30] = {hat = game.ServerStorage.USMPatrol.E2};
	[35] = {hat = game.ServerStorage.USMPatrol.E2};
	[37] = {hat = game.ServerStorage.USMPatrol.E2};
	[40] = {hat = game.ServerStorage.USMPatrol.E2};
	[42] = {hat = game.ServerStorage.USMPatrol.E2};
	[45] = {hat = game.ServerStorage.USMPatrol.E2};
	[50] = {hat = game.ServerStorage.USMPatrol.E2};
	[55] = {hat = game.ServerStorage.USMPatrol.E2};
	[60] = {hat = game.ServerStorage.USMPatrol.E2};
	[61] = {hat = game.ServerStorage.USMPatrol.E2};
	[62] = {hat = game.ServerStorage.USMPatrol.E2};
	[63] = {hat = game.ServerStorage.USMPatrol.E2};
	[66] = {hat = game.ServerStorage.USMPatrol.E2};
	[67] = {hat = game.ServerStorage.USMPatrol.E2};
	[68] = {hat = game.ServerStorage.USMPatrol.E2};
	[70] = {hat = game.ServerStorage.USMPatrol.E2};
			[235] = {hat = game.ServerStorage.USMPatrol.O10};
	[255] = {hat = game.ServerStorage.USMPatrol.E2};
};

local accessremote = game.ReplicatedStorage.Accessories.access

game.ReplicatedStorage.Accessories.access.OnServerEvent:Connect(function(plr, Outfit, shirthat)
			if FloodCheck:Check(plr, accessremote, 0.08333) then
				
		if shirthat == "hat" and Outfit == "USMPatrol" then
			local formalrank = plr:GetRankInGroup(4219097)
			local info = Formals[formalrank]
			print (info)
			if info then
				local g = info.hat
				accessoryspawn(plr,g)
			end
			
			end
			end
		end)

This is what I ended up doing for the script; I made it into a function so I don’t have to copy & paste the entire clone & weld lines of code for each remote event fired, conserving lines of code - and making it easier to edit in the future.