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 7 years ago

groupID = 290188 script.Parent.MouseButton1Click:connect(function() if game.Players.LocalPlayer:IsInGroup(groupID) then game.Players.LocalPlayer.TeamColor = BrickColor.new("Gold") game.Players.LocalPlayer:LoadCharacter() end end)

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 7 years ago
Edited 7 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.

groupID = 290188
local remoteEvent = game.ReplicatedStorage.remoteEvent -- any location really

script.Parent.MouseButton1Click:connect(function(plr)
    if plr:IsInGroup(groupID) then 
    plr.TeamColor = BrickColor.new("Gold")
    remoteEvent:FireServer(plr)
end
end)

Then your server script would be something like:

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

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 — 7y
0
Yes, the local and the normal script, along with the remote event. idkaname8 25 — 7y
0
Ugh, it doesn't work :C Willie3838 5 — 7y
Ad

Answer this question