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
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
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()
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)
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)