Server Script -
local function loadCharacter(player)
local avatar = game.ReplicatedStorage.Morph1
local clone = avatar:Clone()
clone.Parent = game.StarterPlayer
clone.Name = "StarterCharacter"
player:LoadCharacter()
clone:Destroy()
end
local remoteFunction = Instance.new("RemoteFunction")
remoteFunction.Name = "LoadCharacterFunction"
remoteFunction.OnServerInvoke = loadCharacter
remoteFunction.Parent = game:GetService("ReplicatedStorage")
Local Script -
local button = script.Parent
local remoteFunction = game:GetService("ReplicatedStorage"):WaitForChild("LoadCharacterFunction")
button.MouseButton1Click:Connect(function()
local success, errorMessage = pcall(function()
-- Call the server to load the character
remoteFunction:InvokeServer()
end)
if not success then
warn("Error loading character:", errorMessage)
end
end)
16 окт 2024