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

Is there a way to Load Character in a Local Script?

Asked by 8 years ago

I have a simple change team script. When I go into Play Solo, it works fine. But when I go into a Server with 2 or more people, it doesn't work. I'm pretty sure Load Character cant be used in a Local Script, but is there any way to refresh the character without killing them through a local script?

player = game.Players.LocalPlayer

function onClicked()

player.TeamColor = BrickColor.new("Bright blue")
player:LoadCharacter()

end
script.Parent.MouseButton1Click:connect(onClicked)

2 answers

Log in to vote
1
Answered by
Im_Nick 30
8 years ago

Make the server run the :LoadCharacter() function rather then client, because :LoadCharacter() on a local script will throw an error.

There is not a functional way. If you want to do something about like that use a RemoteEvent.

http://wiki.roblox.com/index.php?title=API:Class/RemoteEvent http://wiki.roblox.com/index.php?title=API:Class/Player/LoadCharacter http://prntscr.com/ajzjag

(This method will work with FE)

[!!!]: IF YOU ENCOUNTER ANY ERRORS MESSAGE ME :[!!!]

-- SERVER --

wait()
local event = Instance.new("RemoteEvent", game:GetService("ReplicatedStorage"))
 event.Name = "RespawnEvent"

event.OnServerEvent:connect(function(Player, _)
    if Player then
        Player:LoadCharacter()
    end
end)

-- LOCAL --

wait()
local event = game:GetService("ReplicatedStorage"):WaitForChild("RespawnEvent")
local LocalPlayer = game:GetService("Players").LocalPlayer

function onClicked()
    LocalPlayer.TeamColor = BrickColor.new("Bright blue")
    event:FireServer("Respawn")
end

script.Parent.MouseButton1Click:connect(onClicked)
0
Alright, I got it. Thanks! SirBrayden 35 — 8y
0
If this helped you please accept my answer! :D Im_Nick 30 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

Tell the server to do it

In a script in a RemoteEvent in Workspace:

script.Parent.OnServerEvent:connect((game.Players:GetChildren()[1] or game.Players.PlayerAdded:wait()).LoadCharacter)

In the LocalScript

workspace.LoadCharacter:FireServer()

Answer this question