Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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?

2 comments

0

idk i had the same thing but i had to kill the player for it to take effect, mabye put the script in replicated first? idk if that will do anything

0

I will try that out

1 answer

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)

14 comments

0

Ok, so I tested this out and still nothing is happening at all...not even in to output...this is in a local script too.

0

Yeah, Im very confused now.

0

are your fireing the event on the client? and is the script disabled?

0

The script is not disabled, and I think i am fiering the event on the server? How do I tell?

0

I am pretty clueless when it comes to serverside and cliendside events. I know what they do and all, but i dont know how to properly use the events

0

in the localscript, are you using :FireServer() at all? and if you select the scripts does it say if they are disabled?

0

in the localscript, are you using :FireServer() at all? and if you select the scripts does it say if they are disabled?

0

No the script is not disabled, and no I am not uning :FireServer() anywhere, where shoud i use it and under what conditions?

0

Ok, now im getting this is my output: Players.simcity99.PlayerGui.ScreenGui.Buttons.James.LocalScript:16: attempt to call field 'OnServerEvent' (a userdata value)

0

wait, onserverevent is used in a server script and fireserver() is used in a loca script

0

local*

0

So I should replace OnServerEvent with :FireServer()?

0

So, RemoteEvent:FireServer(onClicked)

0

what script did you post? local or server?

This discussion is preserved as it was. New answers, comments, and votes are closed.