Just in the Title. How do i do? like this:
local player = game.Players.LocalPlayer local character = player.Character.Humanoid local Position = game.Workspace.Computer.Part.Position local Part = game.Workspace.Computer.Part local computer = game.Workspace.Computer.Keyboard.Body.Position local radius = 10 local Animation = Instance.new("Animation") Animation.AnimationId = "http://www.roblox.com/asset/?id=1456127401" local Hacking = character:LoadAnimation(Animation) function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.E then if player:DistanceFromCharacter(computer) <= radius then character:MoveTo(Position) character.MoveToFinished:wait() character.Parent.LowerTorso.CFrame = CFrame.new(character.Parent.LowerTorso.Position,computer) -- Let the player look at computer. Hacking.Looped = true Hacking:stop() wait(0.01) Hacking:play() end end end game:GetService("UserInputService").InputBegan:connect(onKeyPress) character.Running:connect(function(speed) if speed > 0 then Hacking:stop() end end)
My code only worked on one computer. Can't i let them all work? I only want use one local :C Thank you!
So this code gets the closest computer then you can move to the computer . Edit I added the new code follow the Instructions
Note1
This won't work on FE but you can make it work on FE by adding remote events.
Instructions (Important follow carefully)
1.So all the model computers should be in a folder called Computers
2.Put this script in game.StarterPlayer.StarterPlayerScripts
3.So every computer model should have a primary part note very important the primary part is the part the character will go to so put it just infront of the pc with anchored on and cancollide off and the part should be moved upward "like to the y position of the character.
4.note very important the the part where the player looks at like example the computer screen should be name Part i added comments to where that is code the CFrame look vector.
Read more https://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events
You can modify it
Code is tested.
local player local character local isHacking = true function waitForCharcter() while true do player = game.Players.LocalPlayer if player.Character ~= nil then character = player.Character.Humanoid print(player.Character.Name) print("isn nil") return end wait(1) end end waitForCharcter() local allComputers = game.Workspace.Computers:GetChildren() local radius = 10 local Animation = Instance.new("Animation") Animation.AnimationId = "http://www.roblox.com/asset/?id=1456127401" local Hacking = character:LoadAnimation(Animation) local chosenIndex = nil local chosenComputer = nil local computerIndex = 1 function findClosestComputer(character) for i = 2,#allComputers do local distance = player:DistanceFromCharacter(allComputers[computerIndex].PrimaryPart.Position) local nextDistance = player:DistanceFromCharacter(allComputers[i].PrimaryPart.Position) if distance < nextDistance then chosenIndex = computerIndex chosenComputer = allComputers[chosenIndex] else chosenIndex = i chosenComputer = allComputers[i] computerIndex = i end end return chosenComputer end function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.E then local closestComputerPos = findClosestComputer(character) if player:DistanceFromCharacter(closestComputerPos.PrimaryPart.Position) <= radius then character:MoveTo(closestComputerPos.PrimaryPart.Position) character.MoveToFinished:wait() --Makes it work for R6 and R15 if character.RigType == Enum.HumanoidRigType.R15 then --The lookvector character.Parent.LowerTorso.CFrame = CFrame.new(closestComputerPos.PrimaryPart.Position,closestComputerPos.Part.Position) else --The lookvector character.Parent.Torso.CFrame = CFrame.new(closestComputerPos.PrimaryPart.Position,closestComputerPos.Part.Position) end wait(1) isHacking = true while isHacking ~= false do print("playing") wait(Hacking.Length) Hacking:play() end Hacking:Stop() end end end character.Running:connect(function(speed) if speed > 0 then isHacking = false end end) game:GetService("UserInputService").InputBegan:connect(onKeyPress)