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

I wanted create reload player character script but it brokes and only kills player?

Asked by 5 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.
    local p = game.Players:FindFirstChild(name.Text)
    local c = p.Character
    local h = c.Humanoid
    local res = game.ReplicatedStorage.Respawn.MainScript
    res.Parent = game.Workspace
    h.Health = 0
    wait(0.001)
    res.Parent = game.ReplicatedStorage
0
Please help me, thanks. boshjio15854 15 — 5y
0
what u trying to do TheluaBanana 946 — 5y
0
You can use https://developer.roblox.com/api-reference/function/Player/LoadCharacter to reload the players character User#5423 17 — 5y

3 answers

Log in to vote
0
Answered by 5 years ago

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)

local remote = game:GetService("ReplicatedStorage"):WaitForChild("RespawnPlayer")
local res = game:GetService("ReplicatedStorage"):WaitForChild("Respawn"):WaitForChild("MainScript")
res.Parent = workspace

remote:FireServer(name.Text)
wait(0.001)
res.Parent = game:GetService("ReplicatedStorage")

REVISED Server Script (Add this under ServerScriptService)

local remote = Instance.new("RemoteEvent")
remote.Name = "RespawnPlayer"
remote.Parent = game:GetService("ReplicatedStorage")

remote.OnServerEvent:Connect(function(p)
    p:LoadCharacter()
end)
Ad
Log in to vote
0
Answered by 5 years ago

Use :LoadCharacter()

local Player = game.Players:FindFirstChild(name.Text)

--Before this line you should add an event like Button.MouseButton1Click
Player:LoadCharacter()
0
17:06:09.255 - LoadCharacter can only be called by the backend server boshjio15854 15 — 5y
0
that means it's meant to go in a server sided script, if you want to do this from the client you can set up a remote event that tells the server to do it for you strongrussianboy123 68 — 5y
Log in to vote
0
Answered by
JakyeRU 637 Moderation Voter
5 years ago
Edited 5 years ago

Hello! If you want to respawn a player instantly use :LoadCharacter() instead of Humanoid.Health = 0. Here is an example:

wait(10)
game.Players.JakyeRU:LoadCharacter()
-- My character will be respawned after 10 seconds.

EDIT: You can only use the :LoadCharacter() from a Server Script. If you want to use it from a LocalScript then you have to use RemoteEvents.

Answer this question