Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago

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)
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. cherrythetree 130 — 5y
1
use mouse.Target and the mouse.Move event User#23365 30 — 5y
0
i mean you could do what expodo134ALT said but you could use renderstepped instead of mouse.Move theking48989987 2147 — 5y

1 answer

Log in to vote
1
Answered by
gullet 471 Moderation Voter
5 years ago
Edited 5 years ago

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)
0
Thanks dude, we'll stay in touch if I need any aditional help? Okay? AswormeDorijan111 531 — 5y
0
If you need help visit the discord server or post another question here. gullet 471 — 5y
Ad

Answer this question