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

How would I use LoadCharacter() in my GUI?

Asked by
funyun 958 Moderation Voter
9 years ago

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
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.... alphawolvess 1784 — 9y
2
I would personally use a RemoteEvent. Scriptree 125 — 9y

1 answer

Log in to vote
2
Answered by
ImageLabel 1541 Moderation Voter
9 years ago

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()
Ad

Answer this question