GENERAL PRACTICE
Use workspace
instead of game.Workspace
Don't use :FindFirstChild()
to get a player from Players since if an object with the same name as a player was added to the service, it may be picked instead.
Use :WaitForChild()
to make sure a part exists before changing / using it
ISSUES
You can use the :LoadCharacter()
function of a player to make them respawn without the need to die, however this must be done in a Server Script.
Since you are using a LocalScript, you will require a RemoteEvent
NOTES
Your example script doesn't list the local "name" variable so you will have to add this, along with its functional connection to the script.
REVISED LocalScript (Change your above code to this, keeping your connection / name variable)
1 | local remote = game:GetService( "ReplicatedStorage" ):WaitForChild( "RespawnPlayer" ) |
2 | local res = game:GetService( "ReplicatedStorage" ):WaitForChild( "Respawn" ):WaitForChild( "MainScript" ) |
5 | remote:FireServer(name.Text) |
7 | res.Parent = game:GetService( "ReplicatedStorage" ) |
REVISED Server Script (Add this under ServerScriptService)
1 | local remote = Instance.new( "RemoteEvent" ) |
2 | remote.Name = "RespawnPlayer" |
3 | remote.Parent = game:GetService( "ReplicatedStorage" ) |
5 | remote.OnServerEvent:Connect( function (p) |