do you have any idea on how to put the loop inside this since if I put a forever loop it won’t stop
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.Text = ((item.Parent.Health.Value).." / "..(currentHealth.Value))
end
end
end)
i have done tower defense game before and u do this very weird way ur even cloning the gui.
Can u show me the whole gui thingy and i maybe can do the whole script
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.Text = ((item.Parent.Health.Value).." / "..(currentHealth.Value))
cloneHealth.TextLabel.Position = UDim2.new(0, cursor.Hit.p.X , 0, cursor.Hit.p.Y )
end
end
end)