I'm trying to make a simple gui that lets you change your character appearance, then auto respawns you. The problem is, I know that I can't use LoadCharacter in a LocalScript. I really don't want to kill the character, so how would I use LoadCharacter?
--[[This is a LocalScript in the "OK" TextButton. I based the variables on the ScreenGUI object instead of using script.Parent so you could get a clearer understanding of the hierarchy. --]] player = game.Players.LocalPlayer repeat wait() until player.Character character = player.Character gui = script.Parent.Parent.Parent --The ScreenGUI object input = gui.Frame:WaitForChild("Input") --The TextBox ok = gui.Frame:WaitForChild("OK") --The TextButton invalid = gui.Frame:WaitForChild("Invalid") --The TextLabel for errors ok.MouseButton1Click:connect(function() local id = input.Text local baseurl = "http://www.roblox.com/Asset/CharacterFetch.ashx?userId=" if not tonumber(id) then invalid.Text = "Invalid user ID." else invalid.Text = "" player.CharacterAppearance = baseurl..id end end)
You would want to use a RemoteObject to communicate your request from the client to the server. I would recommend using a RemoteEvent in this context, mainly because you don't need anything returned from your request.
Note that my LocalScript isn't passing a player argument because the player is automatically defined as the client from which the LocalScript is running.
local remote -- define remote.OnServerEvent:connect(function (player) player:LoadCharacter() end)
local remote -- define remote:FireServer()