I have this GUI button that fires a remote to a server script. Once I click the button this happens:
ReplicatedStorage.SelectTeam.OnServerEvent:Connect(function(player, team)
player.Team = team
if (team == Teams.A) then
player:LoadCharacter()
elseif (team == Teams.B) then
player:LoadCharacter()
end
end)
Localscript:
local RemoteEvent = game.ReplicatedStorage.SelectTeam
local frame = script.Parent.Frame
local Teams = game:GetService("Teams")
frame.Pathogens.Activated:Connect(function()
RemoteEvent:FireServer(Teams.Pathogens)
end)
frame["Immune System"].Activated:Connect(function()
RemoteEvent:FireServer(Teams["Immune System"])
end)
For the first time, it worked, aka when you first join the game and select your team this script works, then you die, u go back to menu screen and when you select it for the 2nd time, it does not work, what I get is a brief moment of flash then it instantly kills my player. Its hard to explain so here is a video: https://photos.app.goo.gl/M5cK88prPCBsGjzz8
For the GUI resetting, that’s because the ResetOnSpawn property of the ScreenGui object being enabled by default (meaning you can fix this by disabling it).
For the player dying, you don’t necessarily have to make the player’s character load again. You can either just change the player’s character’s position or CFrame, or disable CharacterAutoLoads property of the Players service, and handle it manually.
First you check for the humanoid of the person, And put a event connecting to when that humanoid dies. There is a way that is this one:
-- First you need to disable the CharacterAutoLoads at Players service.
humanoid.Died:Connect(function()
-- Do things for when the player dies
local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
player:LoadCharacter()
end)
I don’t see the issue, your title doesn’t suggest an issue?
When you do :LoadCharacter() on a player, irregardless of whether or not a character already exists the player is reset.
As @OptimisticSide said, you should switch off auto load and switch on ResetOnSpawn. @AstralBlu_e’s code is a technical example (although not sure why he is getting the humanoid in that method if this is being done on the server).
I would suggest reading up on the documentation provided on all of these:
The video would not load for me, this could be an issue on my end however I cannot get this video to work on any platform.
I’m not particularly sure why you’ve put Teams.A and Teams.B when they wouldn’t be valid teams if your client code is specifying the team for you. From your logic:
-- from client from server
Teams.Pathogens ~= Teams.A
There’s no need to call the GetPlayerFromCharacter function. Simply do this:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.Died:Connect(function()
if Player.Team then
Player:LoadCharacter()
end
end)
end)
end)