1. What do I want to achieve? I want that my game’s camera look at a point between two different players.
2. What is the issue? I have a script that works fine, but my problem is that the script doesn’t find humanoidrootparts of all players on server. Instead of that, my script only find a local HRP and a dummy’s HRP.
My Script:
local runService = game:GetService("RunService")
local camera = workspace.CurrentCamera
local character = script.Parent.Parent.Character or script.Parent.Parent.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
runService.RenderStepped:Connect(function()
local P1 = character:WaitForChild("Head")
local P2 = workspace.Part.Head
local between = (P1.position + P2.Position)/2
camera.CFrame = CFrame.new(Vector3.new(between.X,between.Y,between.Z+10), between)
end)
character.Humanoid.AutoRotate = false
I want that the script find all HRP on server, so I could manipulate players’ HRP.
3. What solutions have I tried so far?
Well, I tried to find HRP with an array.
Example:
local HRPs = {
["Plr1"] = --player 1,
["Plr2"] = --player 2
}
But I don’t know how to do that and I search like for 1 month without results… HELP
(I KNOW HOW TO FIND HRP OF A LOCAL PLAYER)
1 Like
Not 100% sure what you are exactly asking for, but do you need to get the HRP of each player on the server? If so, a simple for loop would do:
for _,player in pairs(game.Players:GetPlayers()) do
local char = player.Character
local humanoidRootPart = char.HumanoidRootPart
-- Do other stuff
end
Well, I’m asking for identify the hrp of all players on a server separatly.
Something like this:
local hrp1 = --hrp of player1
local hrp2 = --hrp of player2
btw, I don’t know if the script that you sent me works with what i want to achieve
Ah I see. The best way to do what you need would be to edit the code I previously made to something like this:
local humanoidRootParts = {}
for _,player in pairs(game.Players:GetPlayers()) do
local char = player.Character
local humanoidRootPart = char.HumanoidRootPart
humanoidRootParts[player] = humanoidRootPart
end
This puts the players with their HRPs in a table that can be accessed after.
And how can I manipulate differents hrp? I’m trying that the camera look between 2 players.
In my script I use this:
local between = (P1.position + P2.Position)/2
camera.CFrame = CFrame.new(Vector3.new(between.X,between.Y,between.Z+10), between)
(I appreciate that you answer my post)
Hey! How can I access the array for identify player1 and player2?
Sorry, I’m a beginner in this
local Player1 = humanoidRootParts[player1name]
local Player2 = humanoidRootParts[player2name]
but how can i identify the player1name if i don’t know who are the player 1? With the array? I can’t understand, sorry
you want when a other player is close that the player is ?
no, i want when players join to the server. I’m trying to make a 2D Fighting Game btw
I need the hrps of both players seperatly for this:
local between = (Player1.position + Player2.Position)/2
local humanoidRootParts = {}
repeat wait(1) until #humanoidRootParts == 2
local randomplayer = humanoidRootParts
local Player1 = humanoidRootParts[randomplayer[math.random(1,#randomplayer)]]
randomplayer[Player1] = nil
local Player2 = humanoidRootParts[randomplayer[math.random(1,#randomplayer)]]
randomplayer[Player2] = nil
can you tell me if is work i can’t test for now
Player from HRP:
HRP’s Parent, then find player from character.
HRP from Player:
Player.Character.(Property pointing HRP)
I used (Property pointing HRP) so it works both R6 and R15.
No, it doesn’t apparently:
Players.Player2.PlayerScripts.CameraScript:14: invalid argument #2 to 'random' (interval is empty)
do you add something for add player in table like this :
It’s something wrong? output didn’t show me an error
local humanoidRootParts = {}
local runService = game:GetService("RunService")
local camera = workspace.CurrentCamera
for _,player in pairs(game.Players:GetPlayers()) do
local randomplayer = humanoidRootParts
local char = player.Character
local humanoidRootPart = char.HumanoidRootPart
local Player1 = humanoidRootParts[randomplayer[math.random(1,#randomplayer)]]
local Player2 = humanoidRootParts[randomplayer[math.random(1,#randomplayer)]]
local between = (Player1.position + Player2.Position)/2
randomplayer[Player1] = nil
randomplayer[Player2] = nil
humanoidRootParts[player] = humanoidRootPart
runService.RenderStepped:Connect(function()
camera.CFrame = CFrame.new(Vector3.new(between.X,between.Y,between.Z+10), between)
end)
end
local players = game.Players:GetChildren()
local rootParts = {}
for i,v in pairs(players) do
if v.Character then
if v.Character.HumanoidRootPart then
table.insert(rootParts, v.Character.HumanoidRootPart)
end
end
Then to address them, you just use rootParts[1] and rootParts[2]
sorry i can’t help more i don’t have acces to my computer for test but i can just say you need 1 server script and 1 local script
local script for camera
server script for select player and send to client script when player are selected
because if everything is client player don’t get the same enemy if in 1 server can have more that 2 player
You wrote rootparts[1].position without capital P
I can’t get any results
The output doesn’t show me any error now, so i don’t know what I’m doing wrong