I am trying to pull the StarterCharacter from replicated storage and place it into my StarterPlayer to Change the character.
So, When I click my GUI button I get this in my output log: Players.simcity99.PlayerGui.ScreenGui.Buttons.James.Script:16: attempt to index a nil value.
I am assuming I messed up the remote event.
Here is the code:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = Instance.new("RemoteEvent", ReplicatedStorage)
RemoteEvent.Name = "CharSwap"
local function onClicked()
script["Click Sound"]:Play()
local StarterChar = game.StarterPlayer.StarterCharacter
StarterChar:Destroy()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
RemoteEvent:FireServer()local James = ReplicatedStorage["James"]:Clone()
James.Name = ("StarterCharacter")
James.Parent = game.StarterPlayer
end
RemoteEvent:FireServer(onClicked)

4 comments
full code please. and the Parent argument to Instance.new is deprecated. This is not the full code as the OnServerEvent listener is missing. For now I will assume you did not implement it. Implement it.
Yeah, I didnt implement it, and I dont really know alot about how server and clientside events work.
Oh, and this is the whole script, and its a localscript
You are also passing the function "onClicked" to FireServer. A client can insert malicious code into the function, send the function to the server and the server would blindly call the function, replicating the malicious code to other clients.