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

How would I compare the players location to all other players in the server?

Asked by 4 years ago
Edited 4 years ago

So, I'm trying to find the difference between the player who sent the FireServer request, and all other players in the server to check if they are within 300 studs, I tried this but I recieved the error bad argument expected string got table.

local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage.Remotes:WaitForChild("senseRemote")

remote.OnServerEvent:Connect(function(player)
    for i, v in pairs("game.Players:GetChildren()")
    do
    local inRange = (player.character.HumanoidRootPart.Position -   v.Character.HumanoidRootPart.Position).magnitude
        if inRange < 300 and v.Team.Value ~= player.Team.Value then
            remote:Disconnect(player)
        end
    end
end)
0
I will be adding more code after the in Range statement so changing the format completely won't work for what I need. Feroxidus 83 — 4y
1
I think the player.Team doesn't need a ".value" after it ALSO remove the " between game.Players:GetChildren() (in the loop) TheRealPotatoChips 793 — 4y
0
Thanks Feroxidus 83 — 4y

1 answer

Log in to vote
0
Answered by
TrippyV 314 Donator Moderation Voter
4 years ago
Edited 4 years ago

The "bad argument" error is because you're passing a string inside the pairs method.

local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage.Remotes:WaitForChild("senseRemote")

remote.OnServerEvent:Connect(function(player)
    for i, v in pairs(game.Players:GetChildren()) do
        local inRange = (player.character.HumanoidRootPart.Position - v.Character.HumanoidRootPart.Position).magnitude

        if inRange < 300 and v.Team ~= player.Team then
            remote:Disconnect(player)
        end
    end
end)

If you have any other concerns be sure to comment and we can figure it out :)

Ad

Answer this question