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

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?

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 Donut792 216 — 5y
0
I will try that out simcity99 0 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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)
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. simcity99 0 — 5y
0
Yeah, Im very confused now. simcity99 0 — 5y
0
are your fireing the event on the client? and is the script disabled? the8bitdude11 358 — 5y
0
The script is not disabled, and I think i am fiering the event on the server? How do I tell? simcity99 0 — 5y
View all comments (10 more)
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 simcity99 0 — 5y
0
in the localscript, are you using :FireServer() at all? and if you select the scripts does it say if they are disabled? the8bitdude11 358 — 5y
0
in the localscript, are you using :FireServer() at all? and if you select the scripts does it say if they are disabled? the8bitdude11 358 — 5y
0
No the script is not disabled, and no I am not uning :FireServer() anywhere, where shoud i use it and under what conditions? simcity99 0 — 5y
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) simcity99 0 — 5y
0
wait, onserverevent is used in a server script and fireserver() is used in a loca script the8bitdude11 358 — 5y
0
local* the8bitdude11 358 — 5y
0
So I should replace OnServerEvent with :FireServer()? simcity99 0 — 5y
0
So, RemoteEvent:FireServer(onClicked) simcity99 0 — 5y
0
what script did you post? local or server? the8bitdude11 358 — 5y
Ad

Answer this question