Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to get HUMANOID when cursor is pointed at the "Zombie", "Human" model?

I need a quick few tips on how to get a Humanoid when the Mouse Cursor is pointed at the Model as you point at the Zombie (model) and it shows the GUI of the HP of that zombie.

All I need right now is to get the Humanoid from Pointing the mouse at the model. I've never used something like that in scripts.

This is what I've done so far:

wait(0.5)

local char = game:GetService("Players").LocalPlayer.Character -- I need to make this variable to change to the Model Humanoid EVERYTIME you point at the "Zombie".
local hum = char.Humanoid
	
hum.Changed:Connect(function()
	script.Parent.Frame.Health.Frame.Size = UDim2.new(hum.Health / hum.MaxHealth, 0, 1, 0)
	script.Parent.Frame.Text.TextLabel.Text = math.floor(hum.Health) .. "/" .. hum.MaxHealth
	if hum.Health <= hum.MaxHealth * 0.15 then
		script.Parent.Frame.Health.Frame.BackgroundColor3 = Color3.new(150 / 255, 0, 0)
	else
   		script.Parent.Frame.Health.Frame.BackgroundColor3 = Color3.new(0, 220 / 255, 0)
	end
end)

3 comments

0

Just make a script that you will instance a part and the part is invisible which the part follows your cursor and add a script wherein the part senses the model in touch.

1

use mouse.Target and the mouse.Move event

0

i mean you could do what expodo134ALT said but you could use renderstepped instead of mouse.Move

1 answer

✓ Accepted answer

Check out the wiki article for some info. To detect you could do something like (this is just an example):

local player = game:GetService("Players").LocalPlayer 
local mouse = player:GetMouse()
local current_zombie = nil
mouse:GetPropertyChangedSignal("Target"):Connect(function(hit)
	if hit.Parent.Name == "Zombie" then -- somehow check that it's a part in the zombie
		if hit.Parent == current_zombie then -- check if this zombie is already targeted
			-- do nothing (keep showing gui)
		else
			current_zombie = hit.Parent
			-- remove any existing gui
			-- show new gui
		end
	else
		current_zombie = nil
		-- remove any existing gui
	end
end)

2 comments

0

Thanks dude, we'll stay in touch if I need any aditional help? Okay?

0

If you need help visit the discord server or post another question here.

This discussion is preserved as it was. New answers, comments, and votes are closed.