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

Can someone explain to me the logistics of making a character menu?

Asked by 2 years ago
Edited 2 years ago

For this game I'm attempting to make for fun, I am currently making a menu that changes a character the player looks at, but I'm not sure how to do certain things.

  1. I want to add hair to an npc but I don't know how to do it without using a local script which doesn't attach the hair to the npc.
  2. I want the player to spawn as the character they are viewing but don't know how

My knowledge of Lua is limited but I'm doing this for fun and also to learn so if someone could help me get an idea of how to approach these tasks that'd be great.

1 answer

Log in to vote
1
Answered by
AronYstad 101
2 years ago
Edited 2 years ago

I explained how to fix the hair in another thread. Anyways, as far as I am aware, you can't set a character from a local script, so you will need to use a remote event. Here is the server-side code (the regular script):

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:FindFirstChild("RemoteEvent") or Instance.new("RemoteEvent",ReplicatedStorage)

RemoteEvent.OnServerEvent:Connect(function(player)
    local character = game.Lighting.Character:Clone()
    character.Parent = game.StarterPlayer
    character.Name = "StarterCharacter"
    player:LoadCharacter()
    character:Destroy()
end)

Change game.Lighting.Character to where the character is located. If you want the player to have that character when they respawn as well, you'll just need to turn off auto-loading using this line of code:

game.Players.CharacterAutoLoads = false

and then run the function in the first code block whenever the character dies, maybe with a wait(5) if you want it to be like regular respawns.

Here is the client-side code (local script):

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

RemoteEvent:FireServer()

Just put RemoteEvent:FireServer() in a function to make it fire when you click a button or something.

Anyways, this code will make the player respawn, and idk how to work around that except maybe just changing the CFrame of the player and removing the force field (if necessary), or changing the spawn location. There is also a function called Player:LoadCharacterBlocking, and idk if that's better in this case. Cause it seems like this might make players have the same character if they die on the same frame, while Player:LoadCharacterBlocking stops other scripts if I understood it correctly. Anyways, I hope this at least gets you on the right track. Comment if you have any questions about the code.

Ad

Answer this question