Help with creating a script that when a player goes a certain distance to the part, the player gets sent backwards

The force can be anything, 0,0,0 is the place you want to keep the player from

Oh, so I write a number as the force?

Pretty sure the force is a Vector3, it would be the directional vector of the force IIRC.

1 Like

Do I do something like this?

Or should I put Vector3 (100, 100, 100)?

--server script

local runservice = game:GetService('RunService')
local players = game:GetService('Players')

local part = --were
local max_magnitude = 20 -- maximum magnitude

function getNearPlrs(mag)
  local list = {}
  for index, player in next, players:GetPlayers() do
    local character = player.Character
    if character then
      local root = character:WaitForChild('HumanoidRootPart')
      local distance = (root.Position - part.Position)
      if distance < mag then
        table.insert(list, #list+1, character)
      end
    end
    runservice.Heartbeat:Wait() -- alot players
  end
  return list
end

runservice.Heartbeat:Connect(function()
  local chars = getNearPlrs()
  for _, character in next, chars do
    local root = character:WaitForChild('HumanoidRootPart')
    local look = root.CFrame.LookVector
    root.Position -= look -- if im not wrong, this makes it move backwards
  end
end)

Can you tell me where to put this script?

workspace or serverscript or in the part, just put the part location and you’re done

1 Like

I tested the script, but it seems like nothing is happening; I only put the script in the ServerScriptService.

yes, put the part location


So do I put the part location inside the script?

the “part” variable


1 Like

Sorry if I am asking too many questions; I’m not familiar with scripts.

Can you help me? It seems like it’s not working.
Here is a video of it:

Here is a video from YouTube (Not my video) of something that is similar to what I want to make.

idk i can’t think anything of this again :flushed:

1 Like

It’s ok, I will just try to find tutorials in YouTube.