Local script in gui not recieving client event?

Event is being fired but this specific local script isnt recieving it. I know the event is being fired because i have another local script that is recieving it. I also know that the script is running becuase prints work outside of the function.

repeat task.wait() until game:IsLoaded()
local localPlayer = game:GetService("Players").LocalPlayer

local gui = script.Parent
local StaminaText = gui:WaitForChild("StaminaText")
local Health = gui:WaitForChild("Health")
local StaminaBar = gui:WaitForChild("StaminaBar")


local RS = game:GetService("ReplicatedStorage")
local RSE = RS:WaitForChild("ReplicatedEvents")
local CC = RSE:WaitForChild("ChangeCharacter")

local mycharacter
local mycharacterassets
CC.OnClientEvent:Connect(function(character)
	print("hello")
	mycharacter = character
	mycharacterassets = character.Assets
	StaminaText.Text = "Stamina: "..mycharacterassets.Values.Stamina.Value
end)

The path to the Remote Event might be not correct.

1 Like

can we see the other local script that is correctly receiving the remote?

1 Like

And the server script that fires the RemoteEvent.

1 Like

Server

local Rig = game.ReplicatedStorage.Zinger
local Humanoid = Rig:WaitForChild("Humanoid")
local Description = Humanoid:GetAppliedDescription()
script.Parent.Triggered:Connect(function(Plr)
	--Plr:LoadCharacterWithHumanoidDescription(Description)
	local cloned = Rig:Clone()
	cloned.HumanoidRootPart.CFrame = Plr.Character.HumanoidRootPart.CFrame
	local deletechar = Plr.Character
	cloned.Parent = game.Workspace
	cloned.Name = Plr.Name
	Plr.Character = cloned
	deletechar:Destroy()
	game.ReplicatedStorage.ReplicatedEvents.ChangeCharacter:FireClient(Plr, cloned)
end)

Other local script

repeat task.wait() until game:IsLoaded()
local localPlayer = game:GetService("Players").LocalPlayer

local RS = game:GetService("ReplicatedStorage")
local RSE = RS:WaitForChild("ReplicatedEvents")
local CC = RSE:WaitForChild("ChangeCharacter")

CC.OnClientEvent:Connect(function(character)
	if workspace.CurrentCamera and localPlayer.Character then
		local humanoid = character:FindFirstChildWhichIsA("Humanoid")
		if humanoid then
			workspace.CurrentCamera.CameraSubject = humanoid
		end
	end
end)

Can’t you put both in one Client Event instead of splitting them into multiple local scripts?

The issue is that this specific local script isnt recieving the event. The local script is in a gui, i cant move it to the one that works. If i move the other one to this one, it wont recieve it.

Found the solution. The issue was, whenever the character changed, the gui would also reset, causing the script to not run the function. Moving the script to StarterPlayerScript and moving the gui values inside the function worked out for me. Heres the script for some random person in like 5 years

repeat task.wait() until game:IsLoaded()
local localPlayer = game:GetService("Players").LocalPlayer
local playerGui = localPlayer:WaitForChild("PlayerGui")

local RS = game:GetService("ReplicatedStorage")
local RSE = RS:WaitForChild("ReplicatedEvents")
local CC = RSE:WaitForChild("ChangeCharacter")

local function UpdateGui(character)
	local gui = playerGui:WaitForChild("StatsGui")
	local StaminaText = gui:WaitForChild("StaminaText")

	if character then
		local mycharacterassets = character.Assets

		if mycharacterassets.Values.Stamina then
			StaminaText.Text = "Stamina: " .. mycharacterassets.Values.Stamina.Value
		end
	end
end

CC.OnClientEvent:Connect(UpdateGui)

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