I read that, for some reason it doesn’t work for me.
i have a whole thing in my game that shows enemy name and health and a bar. if i could i would send it to u and a code so it runs perfectly
mind sharing the part where the gui follows the cursor’s position…?
local userInputService = game:GetService("UserInputService")
local camera = game.Workspace.CurrentCamera
local runService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local cursor = player:GetMouse()
function mouseRayCast()
local mousePos = userInputService:GetMouseLocation()
local mouseRay = camera:ViewportPointToRay(mousePos.X +2, mousePos.Y)
local raycastResult = game.Workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 1000)
return raycastResult
end
runService.RenderStepped:Connect(function()
local result = mouseRayCast()
if result and result.Instance then
item = result.Instance
end
end)
player.PlayerGui.ChildAdded:Connect(function(child)
if child.Name == "ShowHealth" then
task.wait(0.05)
child:Destroy()
end
end)
cursor.Move:Connect(function()
if item then
if item.Parent:FindFirstChild("Enemy") then
local cloneHealth = game.ReplicatedStorage.ShowHealth:Clone()
cloneHealth.Parent = player.PlayerGui
local currentHealth = item.Parent.Health
--print(cursor.Hit.p.X, cursor.Hit.p.Y)
cloneHealth.TextLabel.Position = UDim2.new(0, cursor.X , 0, cursor.Y)
cloneHealth.TextLabel.Text = ((item.Parent.Health.Value).." / "..(currentHealth.Value))
end
end
end)
this should fix it i was just wondering if u would like a one made easy and simple way
u even used ray to get the target when mouse has a thing:
mouse.Target and it returns the part its pointing
It doesn’t seem to change anything… hmm…
the problem is it DOES print a difference in the position of the cursor everytime it hits the enemy, but it just doesn’t set the gui’s position to THAT position.
super weird. it rly should set the position
does it still move with the mouse?
does it error anywhere in the scirpt
no, it doesn’t. It’s super weird and I think I have to continue with this tomorrow, I need to go now…
it doesn’t, weird… I still can’t fix the issue
I know I’m like 2 years late, but is this issue fixed now? I think what you are trying to do is that a GUI will pop-up when you aim your cursor at an enemy npc. No need to clone guis, just create a gui already and use .Renderstepped