Note: the place is filteringenabled

I want to get a value from a value inside the player, so I tried at first without using any remotefunctions to get the value, but the bar didn't work online (it only worked in play solo). Then I tired WITH remotefunctions, but it isn't working aswell.

I just kept all my remotefunctions/remoteevents in a folder called RemoteEvents.

localscript:

local healthBar  = script.Parent:WaitForChild("healthBar")
local hungerBar  = script.Parent:WaitForChild("hungerBar")
local thirstBar  = script.Parent:WaitForChild("thirstBar")
local hfill      = healthBar:WaitForChild("Fill")
local hufill     = hungerBar:WaitForChild("Fill")
local tfill      = thirstBar:WaitForChild("Fill")
local plr        = game.Players.LocalPlayer
local repStorage = game:GetService("ReplicatedStorage")
local tremote    = repStorage:WaitForChild("RemoteEvents"):WaitForChild("GetThirst")
local hremote    = repStorage:WaitForChild("RemoteEvents"):WaitForChild("GetHealth")
local huremote   = repStorage:WaitForChild("RemoteEvents"):WaitForChild("GetHunger")
local hhremote   = repStorage:WaitForChild("RemoteEvents"):WaitForChild("GetMaxHealth")

while true do
	local thirst = tremote:InvokeServer(game.Players.LocalPlayer)
	local hunger = huremote:InvokeServer(game.Players.LocalPlayer)
	local health = hremote:InvokeServer(game.Players.LocalPlayer)
	local maxhealth = hhremote:InvokeServer(game.Players.LocalPlayer)
	if plr.Character.Humanoid ~= nil then
		healthBar.Fill.Size = UDim2.new(0, health / maxhealth * healthBar.Size.X.Offset, 0, healthBar.Size.Y.Offset)
	end
	hungerBar.Fill.Size = UDim2.new(0, (hunger / 100) * hungerBar.Size.X.Offset, 0, hungerBar.Size.Y.Offset)
	thirstBar.Fill.Size = UDim2.new(0, (thirst / 100) * thirstBar.Size.X.Offset, 0, thirstBar.Size.Y.Offset)
	wait(0.1)
end

how the reg scripts look like:

local repStorage = game:GetService("ReplicatedStorage")
local remoteFolder = repStorage:WaitForChild("RemoteEvents")
local remote = remoteFolder:WaitForChild("GetHunger")

remote.OnServerInvoke:connect(function(plr)
	return plr.Hunger.Value
end)

This is basically how all the other reg scripts look like, but they just return different things. And yes, the other reg scripts have another remotefunction.

1 comment

0

I was doing OnServerInvoke wrong.