Remote Event Issue

Hello everyone, i am having a problem and dont know how to fix (i suck at scripting), so for my script the “whichcharacter” part doesnt work and shows a error of

  whichcharacter is not a valid member of Folder "ServerStorage.Character"

Any Help!

script (sorry for the unspefic description, i dont know how to explain it)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("CharacterChanging")

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(char)
		remoteEvent.OnServerEvent:Connect(function(player, whichcharacter)
			for _,accessory in ipairs(game.ServerStorage.Character.whichcharacter.Accessory:GetChildren()) do -- the whichcharacter doesnt work at all with the remote event function.
				local added = accessory:Clone()
				char:WaitForChild('Humanoid'):AddAccessory(added)
			end
			for _,clothing in ipairs(game.ServerStorage.Character.whichcharacter.Clothing:GetChildren()) do
				clothing:Clone().Parent = char
			end
		end)

	end)
end)

Use

game.ServerStorage.Character:FindFirstChild(whichcharacter).Accessory:GetChildren()

If you do this then you will be searching for whatever is stored inside the whichcharacter variable rather than search for an object called whichcharacter inside Character

1 Like

it worked!!! thank you very much!

1 Like