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 code:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local createPartEvent = Instance.new("RemoteEvent", ReplicatedStorage) createPartEvent.Name = "CharSwap" local function onClicked() script["Click Sound"]:Play() local StarterChar = game.StarterPlayer.StarterCharacter StarterChar:Destroy() local ReplicatedStorage = game:GetService("ReplicatedStorage") local James = ReplicatedStorage["James"]:Clone() James.Name = ("StarterCharacter") end onClicked().OnServerEvent:Connect(onClicked)
Where did I mess up?
you calling OnServerEvent
on the function, you should be calling that on the remote!
local ReplicatedStorage = game:GetService("ReplicatedStorage") local createPartEvent = Instance.new("RemoteEvent", ReplicatedStorage) createPartEvent.Name = "CharSwap" local function onClicked() script["Click Sound"]:Play() local StarterChar = game.StarterPlayer.StarterCharacter StarterChar:Destroy() local ReplicatedStorage = game:GetService("ReplicatedStorage") local James = ReplicatedStorage["James"]:Clone() James.Name = ("StarterCharacter") end createPartEvent.OnServerEvent:Connect(onClicked)