I'm trying to a make a custom health gui, and I get this error. Help? (I already tried game.Players.LocalPlayer.Character.Humanoid.Health, same error.)
Use both scripts if needed:
--LOCAL SCRIPT-- local RS = game:GetService("ReplicatedStorage") local remotef = RS.RemoteFunctions:WaitForChild("Change3") while true do wait(.0001) local MV = remotef:InvokeServer(workspace:FindFirstChild(script.Parent.Parent.Parent.Parent.Parent.Parent.Name):WaitForChild("Humanoid").Health) -- The problem/error script.Parent.Text = "[H] HEALTH: "..MV end
--SERVER SCRIPT-- function cV (player,healthAmount) while true do wait(.0001) return healthAmount.Value end end game.ReplicatedStorage:WaitForChild("RemoteFunctions").Change3.OnServerInvoke = cV
this is because you are trying to concatenate a number value, try a tostring() function for that
--LOCAL SCRIPT-- local RS = game:GetService("ReplicatedStorage") local remotef = RS.RemoteFunctions:WaitForChild("Change3") while true do wait() local MV =remotef:InvokeServer(workspace:FindFirstChild(script.Parent.Parent.Parent.Parent.Parent.Parent.Name):WaitForChild("Humanoid").Health) -- The problem/error if type(MV) == "number" then local strvMV = tostring(MV) script.Parent.Text = "[H] HEALTH: "..strMV elseif type(MV) == "string" then script.Parent.Text = "[H] HEALTH: "..MV end end
So the script above checks if MV is a number is a string or a number, if it is a string, it concatenates right away, else it turns it into a string and then concatenates it.
function cV (player,healthAmount) while true do wait() return healthAmount end end game.ReplicatedStorage:WaitForChild("RemoteFunctions").Change3.OnServerInvoke = cV
the server script seems fine, although you really don't need that many while loops
You have
healthAmount.Value
If healthAmount is the same as Humanoid.Health, and not a NumberValue Instance then you don't need to add the ".Value".
- TOO MANY LOOPS
- You don't need a server script for this
- There are simpler ways to do this
- Place a
LocalScript
intoStarterCharacterScripts
-- local script only local plr = game.Players.LocalPlayer local Char = script.Parent local Humanoid = Char:WaitForChild('Humanoid') local PlayerGui = plr:WaitForChild('PlayerGui') local TextLabelToDisplayHealth = -- do ur thing here Humanoid.HealthChanged:Connect(function(h) TextLabelToDisplayHealth.Text = h -- h is = to current health -- or TextLabelToDisplayHealth.Text = '[H] Health: '..h -- or TextLabelToDisplayHealth.Text = '[H] Health: '..h..' / '..Humanoid.MaxHealth end)
Use this code, modify to your favoring.
Hopefully this helped you
Best of luck developer.