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

Can anyone fix this script? (Involves LoadCharacter)

Asked by 9 years ago

So I want the player to be able to click a ScreenGui's TextButton and respawn the player without actually killing them

local name = game.Players.LocalPlayer --Get their name.

TextButton.MouseButton1Click:connect(function()
if game.Players:FindFirstChild(name) then --Is there a player with that name?
    game.Players:FindFirstChild(name):LoadCharacter()
end
end)

This is confusing me, i've been looking at sources the past literal 3 hours watching the RT podcast on my other monitor, and I cannot figure this out, I've looked all around and altered this and many others scripts.

This is how it's ordered if it helps | StarterGui ScreenGui TextButton LocalScript

3 answers

Log in to vote
0
Answered by 9 years ago

Try:

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
    player:LoadCharacter()
end)

Simple as that.

1
You can't use LoadCharacter in a local script jakedies 315 — 9y
Ad
Log in to vote
1
Answered by
Muoshuu 580 Moderation Voter
9 years ago

Put this in a LocalScript and you're good

local Player=game.Players.LocalPlayer
TextButton.MouseButton1Click:connect(function()
    Player:LoadCharacter()
end)
0
Thanks for the reply but it didn't work. EastHalo0 15 — 9y
0
Read cntkillme's comment Tuneable 100 — 9y
Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

Or...

local Player = script.Parent.Parent.Parent
script.Parent.MouseButton1Click:connect(function()
    Player:LoadCharacter()
end)

Try this with a regular Script, because it didn't work for me with a LocalScript.

...It's so weird though, because

http://wiki.roblox.com/index.php?title=API:Class/Player/LoadCharacter

told me otherwise.

Answer this question