Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i local two or up model in one local?

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!

6 comments

0

I am checking it out now do you teleport the character to the computer or only let him walk too there

0

And do you want to find the closest computer to the player?

0

Or wait since the radius is the distance that acounts for the closest.

0

Please don't mind my code. They are just a example. my question is: how do i get two or up with one local?

0

Well i wrote you new working code. and tested will post now

0

Ok thanks!

1 answer

✓ Accepted answer

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)


13 comments

0

Omg this is a big script! i'll try it later.

0

If you follow those insctructions it will work I tested it.

0

It make the character walk to the part when E is pressed.

0

Ohh and make sure the things inside the Computers folder is only parts.If you want it to be models let me know.

0

Ohhh my computer actually are models, may you help me? thanks :D

0

By the way, i updated all codes i own.

0

Should the chair be the part the player walks to.

0

I wanna the player hacking by standing xD.

0

I added new code Let me now if you have any questions

0

I combined it with yours.

0

Ok! Thank you!

0

I'm so pappy this is WORKED!! thank you very much :))

0

Cool

This discussion is preserved as it was. New answers, comments, and votes are closed.