Why is my fireclient() not firing after dying once?

ClientScript is a localscript inside StarterCharacterScripts. PlayerInit is a serverscript inside ServerScriptService. When I initially load in, everything prints as expected but when I respawn after dying once, it only prints ‘initializing guis’. I have no idea how to fix this or what is producing the issue. Any help?

PlayerInit

local Players = game:GetService('Players')
local Modules = game:GetService('ReplicatedStorage').Modules
local Characters = game:GetService('ReplicatedStorage').Characters
local Events = game:GetService('ReplicatedStorage').Events
local InitializeBar = Events.InitializeBar
local SetupMoves = Events.SetupMoves
local CharactersModule = require(Characters.CharactersModule)
local Default_Character = 'Itadori'

Players.PlayerAdded:Connect(function(Player)
	local ChosenCharacter = Instance.new("StringValue", Player)
	ChosenCharacter.Value = Default_Character
	ChosenCharacter.Name = 'ChosenCharacter'
	Player.CharacterAdded:Connect(function(Character)
		local CharacterValue = Instance.new("StringValue", Character)
		CharacterValue.Name = 'CharacterValue'
		CharacterValue.Value = ChosenCharacter.Value
		if CharacterValue then
			for i, v in CharactersModule.Characters do
				if i == CharacterValue.Value then
					InitializeBar:FireClient(Player, v.AwakeningTheme)
					SetupMoves:FireClient(Player, v.Base)
					print('initializing guis')
				end
			end
		end
	end)
end)

ClientScript

local Players = game:GetService('Players')
local Events = game:GetService('ReplicatedStorage'):WaitForChild('Events')
local InitializeBar = Events.InitializeBar
local SetupMoves = Events.SetupMoves
local Modules = game:GetService('ReplicatedStorage'):WaitForChild('Modules')
local MovesGuiHandler = require(Modules.MovesGuiHandler)

SetupMoves.OnClientEvent:Connect(function(Base)
	print('SetupMoves')
	for i, v in Base do
		MovesGuiHandler.createMove(v)
	end
end)

InitializeBar.OnClientEvent:Connect(function(awakeningTheme)
	print('InitializeBar')
	local Colors = awakeningTheme.Colors
	MovesGuiHandler.applyTheme(Color3.fromRGB(Colors.R,Colors.G,Colors.B), awakeningTheme.Text)
end)
1 Like

Because your only doing it on the character that was loaded in when you first joined, when the character dies there no event attached to the new character thus why it’s not working

1 Like

As this person has stated

You can easily do this by instead of doing it only for the player you can use the character.

Playerinit remains intact (unchanged)

The only issue is how your clientscript fires it.

Paste this in the clientscript

local Players = game:GetService('Players')
local Events = game:GetService('ReplicatedStorage'):WaitForChild('Events')
local InitializeBar = Events.InitializeBar
local SetupMoves = Events.SetupMoves
local Modules = game:GetService('ReplicatedStorage'):WaitForChild('Modules')
local MovesGuiHandler = require(Modules.MovesGuiHandler)

local function setupEventHandlers()
    print('Setting up event handlers')
    SetupMoves.OnClientEvent:Connect(function(Base)
        print('SetupMoves')
        for i, v in Base do
            MovesGuiHandler.createMove(v)
        end
    end)

    InitializeBar.OnClientEvent:Connect(function(awakeningTheme)
        print('InitializeBar')
        local Colors = awakeningTheme.Colors
        MovesGuiHandler.applyTheme(Color3.fromRGB(Colors.R, Colors.G, Colors.B), awakeningTheme.Text)
    end)
end

setupEventHandlers()

Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        setupEventHandlers()
    end)
end)

This should have fixed your issue.

1 Like

I’m curious could you explain why this would work?

1 Like

I’m assuming his localscript that fires this is the clientscript [as he stated] that’s what should fire it. and the playerinit is the one that handles everything and responds to the client.

This addition simply makes it so that it: checks on player added, uses the player to get their character.

and lastly fires the setupeventhandlers function.

Now why this works is cause once the player is added and the character is added. It will would keep looping this event ‘CharacterAdded’ each time they reset/respawn.

1 Like

CharacterAdded does not seem to respond at all in localscripts under a character instance.

1 Like

try this

workspace.ChildAdded:Connect(function(child)
   if game.Players:FindFirstChild(child.Name) then
      local player = game.Players:FindFirstChild(child.Name)

      local CharacterValue = Instance.new("StringValue", child)
	  CharacterValue.Name = 'CharacterValue'
	  CharacterValue.Value = player.ChosenCharacter.Value
      if CharacterValue then
         for i, v in CharactersModule.Characters do
            if i == CharacterValue.Value then
               InitializeBar:FireClient(player, v.AwakeningTheme)
               SetupMoves:FireClient(player, v.Base)
               print('initializing guis')
            end
         end
      end
   end
end)

Players.PlayerAdded:Connect(function(Player)
	local ChosenCharacter = Instance.new("StringValue", Player)
	ChosenCharacter.Value = Default_Character
	ChosenCharacter.Name = 'ChosenCharacter'
end)

Before the

In PlayerInit, I would add :

Character:WaitForChild("ClientScript")

I’ve made an typo i just noticed.

Not too sure what you mean by this. Even when I made the script wait until ClientScript existed inside the character, it didn’t change anything

Simply put this in the playerinit script. this should work i assume

local Players = game:GetService('Players')
local Modules = game:GetService('ReplicatedStorage').Modules
local Characters = game:GetService('ReplicatedStorage').Characters
local Events = game:GetService('ReplicatedStorage').Events
local InitializeBar = Events.InitializeBar
local SetupMoves = Events.SetupMoves
local CharactersModule = require(Characters.CharactersModule)
local Default_Character = 'Itadori'

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function()
		local ChosenCharacter = Instance.new("StringValue", Player)
		ChosenCharacter.Value = Default_Character
		ChosenCharacter.Name = 'ChosenCharacter'
		Player.CharacterAdded:Connect(function(Character)
			local CharacterValue = Instance.new("StringValue", Character)
			CharacterValue.Name = 'CharacterValue'
			CharacterValue.Value = ChosenCharacter.Value
			if CharacterValue then
				for i, v in CharactersModule.Characters do
					if i == CharacterValue.Value then
						InitializeBar:FireClient(Player, v.AwakeningTheme)
						SetupMoves:FireClient(Player, v.Base)
						print('initializing guis')
					end
				end
			end
		end)
	end)
end)

try this script lil bro, it could possibly work

I must ask, why are you using the workspace to get the player’s character? when there exists ‘CharacterAdded’ event?

Then, after the waitforchild, add a task.wait(0.1) or just send a signal to the server that he is loaded (with a remote event) and do for example Loaded.OnServerEvent:Wait()

Well think about it, the childadded event will always fire regardless, so why dont we piggback off that thing and check if a character has been loaded into workspace and have it do our DIRTY WORK FOR US

pattinson-smile

you can easily disconnect it by setting it as variable… and using workspace isn’t really that innovative if we’re speaking truthfully

Well let’s see if it works for him!

@nahte06 What’s the verdict?

What I mean for the loaded thing is :
Client :

-- Do all things
Loaded:FireServer()

Server :

Loaded.OnServerEvent:Wait()
InitializeBar:FireClient(player, v.AwakeningTheme)
--Etc
1 Like

I’ve tried both prior solutions and none of them work. However if I implement a wait it works as intended.

1 Like

just add task.wait() not wait() – if we’re talking about in a function and not using events

and you shall be good to go

1 Like