Any Idea why this RemoteEvent might not be firing?

I have a ServerScript (below) that is meant to generate character values and change character appearance, and then fire a RemoteEvent in replicated storage sending the Data to the client of the Player who clicked the button.

DataScript = require(game.ReplicatedStorage.Modules.CharacterData)
CharacterTemplate = game.ReplicatedStorage.ReplicatedAssets.Char


script.Parent.ClickDetector.MouseClick:Connect(function(Player)
	local Pos = Player.Character.HumanoidRootPart.CFrame
	Player.Character = nil
	Player = game.Players:FindFirstChild(Player.Name)
	local function ClearModel()
		Player.Character = CharacterTemplate:Clone()
		Player.Character.HumanoidRootPart.CFrame = Pos
		
		Player.Character.Parent = game.Workspace
	end
	
	ClearModel()
	
	local Data = DataScript.GenerateCharacter()
	
	
	local SkinColor = Data.Appearance.SkinColor:Clone()
	SkinColor.Parent = Player.Character

	print(Data)
	for i, v in Data.Appearance.Hair do
		local Hair = v:Clone()
		Hair.Parent = Player.Character
		if Hair.Handle:FindFirstChild("Mesh") then
			Hair.Handle.Mesh.TextureId = Data.Appearance.HairColor.Texture
		elseif Hair.Handle:FindFirstChild("SpecialMesh") then
			Hair.Handle.SpecialMesh.TextureId = Data.Appearance.HairColor.Texture
		end
	end
	
	
	game.ReplicatedStorage.StatScreenEvent:FireClient(Player, Data)
end)

The issue is that it doesn’t seem to be firing at all, I’ve tried changing it to my username specifically, or using FireAllClients and my LocalScript (below) located in the StarterGUI does not respond. I tested it in another script that simply fires the event to all clients after 4 seconds have passed and it seems to at the very least fire (albiet causing an error due to lack of data parameters), but I can’t seem to figure out why it’s not working in the script above. Any help would be greatly appreciated.

local StatScreenEvent = game.ReplicatedStorage.StatScreenEvent

StatScreenEvent.OnClientEvent:Connect(function(Data)
	print("hello")
	script.Parent["Rarity: "].Text = "Rarity: "..Data.Rarity
	script.Parent["Race: "].Text = "Race: "..Data.Race.Name
	script.Parent["Weapon:"].Text = "Weapon: "..Data.Weapon
	
	for i, v in Data.Traits do
		local TraitLabel = Instance.new("TextLabel")
		TraitLabel.Text = v.Name
		TraitLabel.Size = UDim2.new(1, 0, 0, 100)
		TraitLabel.Parent = script.Parent.ScrollingFrame
		
	end
end)
1 Like

What does print(Player) show if you place it before the StatScreenEvent:FireClient() line?

1 Like

It prints the username of the player who pressed it. In my case it’d print LuxSaar

1 Like

And you’re saying the connection to OnClientEvent doesn’t work (nothing printing to output)? I could easily be wrong, but it might be that the client connection isn’t made before the server fires the event.
I’m just extremely confused since you initially said that it didn’t fire, but then at some point it started working.

the serverscript is working perfectly fine, it’s the localscript that isn’t running at all. If I put the print statement before StatScreenEvent:FireClient(), it would simply print the player who pushed the button serverside. If I were to instead place the print statement in the localscript (in the function that is), it would not print anything at all.

Is the signal from the server being received by the target client?

No. That is my main issue. In fact, even if I fire it to every client at once, it does not get received

I modified the code try this:
local DataScript = require(game.ReplicatedStorage.Modules.CharacterData)
local CharacterTemplate = game.ReplicatedStorage.ReplicatedAssets.Char

local function ClearModel(Player, Pos)
local NewCharacter = CharacterTemplate:Clone()
NewCharacter.HumanoidRootPart.CFrame = Pos
NewCharacter.Parent = game.Workspace
Player.Character = NewCharacter
end

script.Parent.ClickDetector.MouseClick:Connect(function(Player)
local Pos = Player.Character.HumanoidRootPart.CFrame
Player.Character = nil
Player = game.Players:FindFirstChild(Player.Name)

ClearModel(Player, Pos)

local Data = DataScript.GenerateCharacter()

local SkinColor = Data.Appearance.SkinColor:Clone()
SkinColor.Parent = Player.Character

for i, v in ipairs(Data.Appearance.Hair) do
	local Hair = v:Clone()
	Hair.Parent = Player.Character
	local Mesh = Hair.Handle:FindFirstChildWhichIsA("Mesh") or Hair.Handle:FindFirstChildWhichIsA("SpecialMesh")
	if Mesh then
		Mesh.TextureId = Data.Appearance.HairColor.Texture
	end
end

game.ReplicatedStorage.StatScreenEvent:FireClient(Player, Data)

end)

1 Like

All this did for me was mess up my camera unfortunately.

Let me simplify it, since there’s no reason for me to have written my full serverscript here
This down below does not fire the local script that I wrote in my original post.

script.Parent.ClickDetector.MouseClick:Connect(function(Player)
	game.ReplicatedStorage.StatScreenEvent:FireClient(Player)
end)

Like for example, this script fires my client just fine. It has to be a problem with the clickdetector interaction, because even firing all clients on my original script does not work.

local CharData = require(game.ReplicatedStorage.Modules.CharacterData)


wait(4)
game.ReplicatedStorage.StatScreenEvent:FireClient(game.Players.LuxSaar, CharData.GenerateCharacter())

I found the problem, It was that my character was resetting and then it didn’t have time to load the GUI, I fixed it by adding a wait() between the ClearModel() function and the rest of the script

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.