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

How would I use LoadCharacter() in my GUI?

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)

2 comments

2

I'd say the Bindable or server thingies, obviously the way I'm saying it shows I don't know how to use them, but I'm pretty sure that's what you'd do....

2

I would personally use a RemoteEvent.

1 answer

✓ Accepted answer

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.

Server

local remote -- define 

remote.OnServerEvent:connect(function (player)
	player:LoadCharacter()
end)

Client

local remote -- define

remote:FireServer()

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