Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I am trying to swap out StarterCharacters by clicking a GUI button and it is not working?

Asked by 5 years ago
Edited 5 years ago

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)
0
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. User#19524 175 — 5y
0
Yeah, I didnt implement it, and I dont really know alot about how server and clientside events work. simcity99 0 — 5y
0
Oh, and this is the whole script, and its a localscript simcity99 0 — 5y
0
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. User#19524 175 — 5y

Answer this question