RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"part that follows you and if you dont use a tool to hit it back it kills you"
To create a part that follows a player and can be hit back with a tool, you'll need to write a script that handles the following behavior and the interaction with the tool. Here's an example of how you might script this in Roblox using Lua: ```lua -- Server Script local part = Instance.new("Part", workspace) part.Name = "FollowPart" part.Size = Vector3.new(2, 2, 2) part.Position = Vector3.new(0, 3, 0) part.Anchored = false part.BrickColor = BrickColor.new("Bright red") local toolName = "HitTool" -- The name of the tool that can hit the part back -- Function to make the part follow the nearest player local function followPlayers() while part:IsDescendantOf(workspace) do local closestPlayer = nil local minDistance = math.huge for _, player in pairs(game.Players:GetPlayers()) do if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then local distance = (player.Character.HumanoidRootPart.Position - part.Position).magnitude if distance < minDistance then closestPlayer = player minDistance = distance end end end if closestPlayer then local targetPosition = closestPlayer.Character.HumanoidRootPart.Position local direction = (targetPosition - part.Position).unit part.Velocity = direction * 10 -- Adjust the speed as needed end wait(0.1) end end -- Function to handle the interaction with the tool local function onHit(hit) if hit.Parent:FindFirstChildWhichIsA("Tool") and hit.Parent.Tool.Name == toolName then part.Velocity = -part.Velocity * 2 -- Adjust the force as needed end end -- Connect the Touched event to the onHit function part.Touched:Connect(onHit) -- Start following players followPlayers() ``` For the part to kill the player if they don't hit it back with the tool, you can modify the `followPlayers` function to include a check that damages the player if the part gets too close: ```lua -- Add this inside the followPlayers function, within the if closestPlayer then block if minDistance < 2 then -- Adjust the kill distance as needed closestPlayer.Character.Humanoid:TakeDamage(100) -- Adjust the damage as needed end ``` Please note that this script assumes you have a tool named "HitTool" that players can use to hit the part back. You'll need to create this tool separately and ensure it's available to players in the game. Remember to adjust the values for speed, force, kill distance, and damage according to your game's requirements. This script should be placed in a Script object within the ServerScriptService or Workspace.