Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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!

0
I am checking it out now do you teleport the character to the computer or only let him walk too there PlaasBoer 275 — 6y
0
And do you want to find the closest computer to the player? PlaasBoer 275 — 6y
0
Or wait since the radius is the distance that acounts for the closest. PlaasBoer 275 — 6y
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? MEndermanM 73 — 6y
View all comments (2 more)
0
Well i wrote you new working code. and tested will post now PlaasBoer 275 — 6y
0
Ok thanks! MEndermanM 73 — 6y

1 answer

Log in to vote
0
Answered by
PlaasBoer 275 Moderation Voter
6 years ago
Edited 6 years ago

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)


0
Omg this is a big script! i'll try it later. MEndermanM 73 — 6y
0
If you follow those insctructions it will work I tested it. PlaasBoer 275 — 6y
0
It make the character walk to the part when E is pressed. PlaasBoer 275 — 6y
0
Ohh and make sure the things inside the Computers folder is only parts.If you want it to be models let me know. PlaasBoer 275 — 6y
View all comments (9 more)
0
Ohhh my computer actually are models, may you help me? thanks :D MEndermanM 73 — 6y
0
By the way, i updated all codes i own. MEndermanM 73 — 6y
0
Should the chair be the part the player walks to. PlaasBoer 275 — 6y
0
I wanna the player hacking by standing xD. MEndermanM 73 — 6y
0
I added new code Let me now if you have any questions PlaasBoer 275 — 6y
0
I combined it with yours. PlaasBoer 275 — 6y
0
Ok! Thank you! MEndermanM 73 — 6y
0
I'm so pappy this is WORKED!! thank you very much :)) MEndermanM 73 — 6y
0
Cool PlaasBoer 275 — 6y
Ad

Answer this question