Values not showing

I want to make a hovering gui, it worked perfectly but the problem is that the value of mobname and hp is not changing.

local HealthGui = script.Parent
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

while wait() do
	local mouse = Players.LocalPlayer:GetMouse()
	script.Parent.Frame.Position = UDim2.new(0,mouse.X,0,mouse.Y)
	local Target = mouse.Target
	if Target then
		if Target.Parent == workspace.Mobs then
			if Target:FindFirstChildOfClass("Humanoid") then
				local humanoid = Target:WaitForChild("Humanoid")
				local Percent = humanoid.Health / humanoid.MaxHealth
				HealthGui.Frame.Position = UDim2.fromOffset(mouse.X, mouse.Y)
				HealthGui.Frame.MobName.Text = "Fleshling"
				HealthGui.Frame.ShowHP.Text = humanoid.Health .. "/ " .. humanoid.MaxHealth
				HealthGui.Frame.Visible = true
			else
				HealthGui.Frame.Visible = false    
			end
		end
	end
end

no errors

Hi I think this needs to be in a server script or you need to fire a remote event to the server to change the value. Is this in the client?

yes, I made this in a screengui as a local script

I’m assuming you’re talking about the textlabel? The MobName textlabel obviously won’t change because you have it set as just “Fleshling”:

HealthGui.Frame.MobName.Text = “Fleshling”

Not sure about why the HP isn’t changing; it’s probably an issue with how the damage is being taken.

1 Like

yes you are correct, I’ll think about it

1 Like

Ah what you want to do is fire a remote event to the server and in the server script

Local script:
RepStorage.Event:FireServer()

Server script
RepStorage.Event.OnClientEvent:connect(function(player)
player.MyStat.Value = value
end)

I’ll try this as soon as possible

1 Like

did you get mixed up with the scripts? I think you can’t use OnClientEvents in server scripts

still doesn’t work, or I might have just typed it out wrong.

Server Script:

local RepStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

RepStorage.Events.Event.OnServerEvent:connect(function(plr)
	local mouse = Players.LocalPlayer:GetMouse()
	local Target = mouse.Target
	local humanoid = Target:WaitForChild("Humanoid")
	local Percent = humanoid.Health / humanoid.MaxHealth
	plr.PlayerGui.mobhp.Frame.mobName.Text = Target.Parent.Name
	plr.PlayerGui.mobhp.Frame.HP.Text = humanoid.Health .. "/ " .. humanoid.MaxHealth
end)

Local Script:

local HealthGui = script.Parent
local RunService = game:GetService("RunService")
local RepStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

while wait() do
	local mouse = Players.LocalPlayer:GetMouse()
	script.Parent.Frame.Position = UDim2.new(0,mouse.X,0,mouse.Y)
	local Target = mouse.Target
	if Target then
		if Target.Parent == workspace.Mobs then
			if Target:FindFirstChildOfClass("Humanoid") then
				local humanoid = Target:WaitForChild("Humanoid")
				local Percent = humanoid.Health / humanoid.MaxHealth
				HealthGui.Frame.Position = UDim2.fromOffset(mouse.X, mouse.Y)
				RepStorage.Events.Event:FireServer()
--				HealthGui.Frame.mobName.Text = "Fleshling"
--				HealthGui.Frame.HP.Text = humanoid.Health .. "/ " .. humanoid.MaxHealth
				HealthGui.Frame.Visible = true
			else
				HealthGui.Frame.Visible = false    
			end
		end
	end
end

Where is the “HealthGui” located?

maybe it’s because the target in the script is a part of the mob so try
if Target.Parent.Parent == workspace.Mobs then
and
if Target.Parent:FindFirstChild(“Humanoid”) then
and also since you already have runService defined use runService.RenderStepped:Connect(function()

end)
instead of while wait() do

1 Like

Try this:

local HealthGui = script.Parent
local RunService = game:GetService("RunService")
local RepStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

while wait() do
	local mouse = Players.LocalPlayer:GetMouse()
	script.Parent.Frame.Position = UDim2.new(0,mouse.X,0,mouse.Y)
	local Target = mouse.Target
	if Target then
		if Target.Parent.Parent == workspace.Mobs then
			if Target.Parent:FindFirstChildOfClass("Humanoid") then
				local humanoid = Target.Parent:WaitForChild("Humanoid")
				local Percent = humanoid.Health / humanoid.MaxHealth
				HealthGui.Frame.Position = UDim2.fromOffset(mouse.X, mouse.Y)
				RepStorage.Events.Event:FireServer()
--				HealthGui.Frame.mobName.Text = "Fleshling"
--				HealthGui.Frame.HP.Text = humanoid.Health .. "/ " .. humanoid.MaxHealth
				HealthGui.Frame.Visible = true
			else
				HealthGui.Frame.Visible = false    
			end
		end
	end
end
local RepStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

RepStorage.Events.Event.OnServerEvent:connect(function(plr)
	local mouse = Players.LocalPlayer:GetMouse()
	local Target = mouse.Target
	local humanoid = Target.Parent:WaitForChild("Humanoid")
	local Percent = humanoid.Health / humanoid.MaxHealth
	plr.PlayerGui.mobhp.Frame.mobName.Text = humanoid.Parent.Name
	plr.PlayerGui.mobhp.Frame.HP.Text = humanoid.Health .. "/ " .. humanoid.MaxHealth
end)
1 Like

Now there’s a new error:
ServerScriptService.Script:5: attempt to index nil with 'GetMouse'

I really don’t know how to solve attempt to index nil wil ‘x’ errors

its located in startergui of course

you can’t get the mouse of the player from a server script. So, you’d have to use arguments for this.
Try this:

local HealthGui = script.Parent
local RunService = game:GetService("RunService")
local RepStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

RunService.RenderStepped:Connect(function()
	local mouse = Players.LocalPlayer:GetMouse()
	script.Parent.Frame.Position = UDim2.new(0,mouse.X,0,mouse.Y)
	local Target = mouse.Target
	if Target then
		if Target.Parent.Parent == workspace.Mobs then
			if Target.Parent:FindFirstChildOfClass("Humanoid") then
				local humanoid = Target.Parent:WaitForChild("Humanoid")
				local Percent = humanoid.Health / humanoid.MaxHealth
				HealthGui.Frame.Position = UDim2.fromOffset(mouse.X, mouse.Y)
				RepStorage.Events.Event:FireServer(humanoid)
--				HealthGui.Frame.mobName.Text = "Fleshling"
--				HealthGui.Frame.HP.Text = humanoid.Health .. "/ " .. humanoid.MaxHealth
				HealthGui.Frame.Visible = true
			else
				HealthGui.Frame.Visible = false    
			end
		end
	end
end)
local RepStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

RepStorage.Events.Event.OnServerEvent:connect(function(plr, humanoid)
	local Percent = humanoid.Health / humanoid.MaxHealth
	plr.PlayerGui.mobhp.Frame.mobName.Text = humanoid.Parent.Name
	plr.PlayerGui.mobhp.Frame.HP.Text = humanoid.Health .. "/ " .. humanoid.MaxHealth
end)

Hi sorry I’m on PC now - I was on phone so it was really hard to type. You got it right however you want in the server script the player’s mouse as a parameter which you will define in the local script e.g.

LOCAL SCRIPT:

local Mouse = player:GetMouse()
Event:FireServer(Mouse.hit.Position)

SERVER SCRIPT:

Event.OnServerEvent:Connect(function(player,mousepos)
print(mousepos)
end)
1 Like

mark this as solution, since you made the post

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