RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"Make my rig called R15 Dummy follow players and it will damage them by 0.7 if it touches them"
local RunService = game:GetService("RunService") local Players = game:GetService("Players") local r15Dummy = game.Workspace.R15Dummy local humanoid = r15Dummy.Humanoid local root = r15Dummy.HumanoidRootPart local debounce = false function findNearestPlayer() local playerList = Players:GetPlayers() local nearestPlayer = nil local distance = nil local direction = nil for _, player in pairs(playerList) do local character = player.Character if character then local distanceVector = character.PrimaryPart.Position - root.Position if not nearestPlayer then nearestPlayer = player distance = distanceVector.Magnitude direction = distanceVector.Unit elseif distanceVector.Magnitude < distance then nearestPlayer = player distance = distanceVector.Magnitude direction = distanceVector.Unit end end end return nearestPlayer, distance, direction end local function onTouched(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then if hit.Parent:FindFirstChild("Humanoid") ~= nil then if not debounce then debounce = true hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 0.7 wait(1) debounce = false end end else print("Tried to damage an NPC, it was blocked.") end end RunService.Heartbeat:Connect(function() local nearestPlayer, distance, direction = findNearestPlayer() if nearestPlayer then humanoid:Move(direction) end end) root.Touched:Connect(onTouched)