NPC Part Hopper Script

This script makes an NPC move to a part and back to its original position when clicked.

local NPC = script.Parent -- Change this to the path of your NPC
local part = game.Workspace.Part -- Change this to the path of the part you want the NPC to move to
local debounce = false

local function onClicked()
    if not debounce then
        debounce = true
        local originalPosition = NPC.HumanoidRootPart.CFrame
        NPC.Humanoid:MoveTo(part.Position)
        NPC.Humanoid.MoveToFinished:Wait()
        wait(1)
        NPC.Humanoid:MoveTo(originalPosition.p)
        NPC.Humanoid.MoveToFinished:Wait()
        debounce = false
    end
end

NPC.ClickDetector.MouseClick:Connect(onClicked)

You can put the script in the StarterPlayerScripts or StarterCharacterScripts folder in Roblox Studio. This will make the script run for every player that joins your game. You can also put the script in a Script object within the NPC model itself, which will make the script run only for that specific NPC.
To create a new script, right-click on the location where you want to put the script (e.g. StarterPlayerScripts), select Insert Object, and then select Script. This will create a new script object. You can then double-click on the script to open it and paste the code into the script editor.

– Future Script Plans

  • Anti Cheat Script: Someone runs a command in console or a command that shows up in console, Devs show up, and then banned in game
1 Like