Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I can not bring information FilteringEnabled LeaderStats to Custom HealthBar why ?

Sorry if its hard to undestand , I used Google Translator for make that :3

This is the first time I do something with filtering enabled, I have no idea what to use on certain occasions then i am having some troubles, I did 1 script that creates in ServerStorage a folder with the basic values to make a Health Bar ( Max Health and Health )

Leaderstats script :

game.Players.PlayerAdded:connect(function(Player)
	local Folder = Instance.new("Folder" , game.ServerStorage)
	Folder.Name = Player.Name
	
	PlayerStats = {"Health" , "MaxHealth"}
	PlayerStatsValues = {100,100}
	ValuesTypes = {"IntValue" ,"IntValue"}
	
	AllValues = {}
	
	for i = 1,#PlayerStats do
		local Value = Instance.new(ValuesTypes[i])
		Value.Parent = Folder
		Value.Value = PlayerStatsValues[i]
		Value.Name = PlayerStats[i]
		
		table.insert(AllValues , Value)
	end
	
	for i,Value in pairs(AllValues) do
		Value.Changed:connect(function()
			game.ReplicatedStorage.Remotes.StatsEvent:FireAllClients(Value.Name , Value.Value)
		end)
	end
end)

I rarely use tables but since I'm doing my first game I wanted to make things easier to edit and not make 1000 lines for make player stats.

From that moment things have complicated, I tried to give the information to the serverevent to transfer it to StarterGui to modify the bar of life to the desired value, I did it manually and I modified the value in Solo Mode, it works perfectly well, but when using Multiplayer it is not able to do anything, I tried to do the same thing but I used the function OnClientEvent and FireAllClients, I thought it would work if I specify which player would have the modified life bar and so could make a player list with life of all players, but nothing happened.

StarterGui Script with OnClientEvent :


local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

--// Services
local ReplicatedStorage = game:GetService('ReplicatedStorage')

--//Remotes
local Remotes = ReplicatedStorage:WaitForChild('Remotes')
local StatsEvent = Remotes:WaitForChild('StatsEvent')

--// Guis
local Class = script.Parent:WaitForChild('Class')
local Stats = script.Parent:WaitForChild('Stats')

StatsEvent.OnClientEvent:Connect(function(player,Request,Num)
	if Request == "Health" then
	Player.StarterGui.Stats.Health.HealthBar:TweenSize(UDim2.new(Num/100,0,0,10),"Out",	"Linear",0.1)
	end
end)

No error occured with these scripts, they just do not work and I need help to make the life bar work. A good explanation can help me a lot to do the rest of the work.

Another thing I do not know how to do in Filtering Enabled :

How i change the player value in the folder

1 answer

✓ Accepted answer

English (Ir a la versión en español si quieres español)

I think I've just found the problem:

game.ReplicatedStorage.Remotes.StatsEvent:FireAllClients(Value.Name , Value.Value) is sending all Players the value. There are two ways to fix this:

One, Check if the value's name matches with player name.

StatsEvent.OnClientEvent:Connect(function(player,Request,Num)
	if Request == "Health" and player == Player.Name then
		Player.StarterGui.Stats.Health.HealthBar:TweenSize(UDim2.new(Num/100,0,0,10),"Out", "Linear",0.1)
	end
end)

Two, use :FireClient() instead.

for i,Value in pairs(AllValues) do
	Value.Changed:connect(function()
		local Player = game.Players:FindFirstChild(Value.Name)
		game.ReplicatedStorage.Remotes.StatsEvent:FireAllClients(Player, Value.Value)
	end)
end

Spanish (Used Google Translate, utiliza Google Translate)

Creo que acabo de encontrar el problema:

game.ReplicatedStorage.Remotes.StatsEvent:FireAllClients(Value.Name , Value.Value)está enviando a todos los jugadores el valor. Hay dos formas de arreglar esto:

Uno, Comprueba si el nombre del valor coincide con el nombre del jugador.

StatsEvent.OnClientEvent:Connect(function(player,Request,Num)
	if Request == "Health" and player == Player.Name then
		Player.StarterGui.Stats.Health.HealthBar:TweenSize(UDim2.new(Num/100,0,0,10),"Out", "Linear",0.1)
	end
end)

Dos, utilizar :FireClient() en lugar.

for i,Value in pairs(AllValues) do
	Value.Changed:connect(function()
		local Player = game.Players:FindFirstChild(Value.Name)
		game.ReplicatedStorage.Remotes.StatsEvent:FireClient(Player, Value.Value)
	end)
end

3 comments

0

Well , i my "PlayerGui" name in script is named "StarterGui" , But that was not the gltch , and you script it not perfect have some erros in strings , but i fixed they , but you made me fix it and i learned new things , Thanks alot :D , and i dont speak Spanish XD

0

rip English

0

oh RIP, sorry. I'm glad I helped :D

This discussion is preserved as it was. New answers, comments, and votes are closed.