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

LoadCharacter can only be called by the backend server?

Asked by 7 years ago

Switch Team, how to fix and why it not works?

Error: LoadCharacter can only be called by the backend server

LocalScript:

script.Parent.MouseButton1Click:connect(function()
    game.Players.LocalPlayer.TeamColor = BrickColor.new("Light stone grey")
    game.Players.LocalPlayer:LoadCharacter()
    print(game.Players.LocalPlayer.Name.." has changed team to "..script.Parent.Name.." team!")
end)

1 answer

Log in to vote
3
Answered by 7 years ago

Well, if I recall correctly, LoadCharacter can only be called on the Server. To use LoadCharacter in this sense, you'd have to use A RemoteEvent. Here's an example:

Hierarchy: ReplicatedStorage.LoadChar[RemoteEvent] ServerScriptService.RemoteHandler[Script]

LocalScript:

script.Parent.MouseButton1Click:connect(function()
    game.Players.LocalPlayer.TeamColor = BrickColor.new("Light stone grey")
    game.Players.LocalPlayer:LoadCharacter() --game:GetService("ReplicatedStorage")
    print(game.Players.LocalPlayer.Name.." has changed team to "..script.Parent.Name.." team!")
end)

ServerScript:

game:GetService("ReplicatedStorage").LoadChar.OnServerEvent:connect(function(player)
    player:LoadCharacter()
end)

(Please Note: I wrote this in the ScriptingHelper's question editor, so pardon any mistakes.)

Ad

Answer this question