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

Making a player respawn when they click a GUI in a Local Script?

Asked by 8 years ago
01groupID = 290188
02 
03 
04script.Parent.MouseButton1Click:connect(function()
05    if game.Players.LocalPlayer:IsInGroup(groupID) then
06 game.Players.LocalPlayer.TeamColor = BrickColor.new("Gold")
07game.Players.LocalPlayer:LoadCharacter()
08 
09end
10end)

This is what I have, it works in Studio, but doesn't work live. From what I heard, LoadCharacter() only works in Server Scripts, but I can't access LocalPlayer in a Server Script.

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

You could try RemoteEvents which you can pass the plr argument which you declare in the function at line 4.

That'd require a new script and a remote event though, and your local script would like something like this.

1groupID = 290188
2local remoteEvent = game.ReplicatedStorage.remoteEvent -- any location really
3 
4script.Parent.MouseButton1Click:connect(function(plr)
5    if plr:IsInGroup(groupID) then
6    plr.TeamColor = BrickColor.new("Gold")
7    remoteEvent:FireServer(plr)
8end
9end)

Then your server script would be something like:

1game.ReplicatedStorage.remoteEvent.OnServerEvent:connect(function()
2    plr.LoadCharacter()
3end

That's the long way of doing it, and there's probably another function or a fix out there to load character easier. But hey, this is a way to learn.

I'm also a very new scripter, so I could VERY well be wrong there, but I believe that'll work out well.

0
So i'd need two scripts? Willie3838 5 — 8y
0
Yes, the local and the normal script, along with the remote event. idkaname8 25 — 8y
0
Ugh, it doesn't work :C Willie3838 5 — 8y
Ad

Answer this question