Hello. I have a function to determine the mass of a cube and its position. A player cannot absorb cubes with a mass greater than his. I need to make a function to repel the player from cubes with more mass than him. All cubes on the field except the player’s cube are represented in “allheads”. Please help me to write a function.
local function tpFromBigHeads()
for i, v in pairs(allheads) do
local distance = (v["part"].Position - me.Character.HumanoidRootPart.Position).Magnitude
if v["score"] > getPlayerSize() and distance < 5 then
--repel
end
end
end
local function tpFromBigHeads()
for i, v in pairs(allheads) do
local distance = (v["part"].Position - me.Character.HumanoidRootPart.Position).Magnitude
if v["score"] > getPlayerSize() and distance < 5 then
local Character = me.Character
local RootPart = Character.HumanoidRootPart
local KnockbackDirection = (RootPart.Position - v.part.Positon).Unit
-- defining knockback force by the difference in masses of the player and the cube
local KnockbackMagnitude = v["score"] - getPlayerSize() -- could be changed to a constant value
-- function below knocks the player off his feet
-- remove if you dont want that
task.spawn(function()
local Humanoid = Character.Humanoid
Humanoid.PlatformStand = false
task.wait(0.2) -- time to wait before getting up
Humanoid.PlatformStand = true
end)
-- applying knockback
RootPart.AssemblyLinearVelocity = KnockbackDirection * KnockbackMagnitude
end
end
end
local function tpFromBigHeads()
local hrp = me.Character.HumanoidRootPart
local playerSize = getPlayerSize()
for i, v in pairs(allheads["part"]) do
--print(v)
--print(v.Position)
--print(hrp.Position)
local distance = (v.Position - hrp.Position).Magnitude
--print(distance)
if allheads["score"][i] > playerSize and distance < 30 then
print(allheads["score"][i])
print("is greater then")
print(playerSize)
local Character = me.Character
--Humanoid.PlatformStand = true
local KnockbackDirection = (hrp.Position - v.Position).Unit
-- defining knockback force by the difference in masses of the player and the cube
--local KnockbackMagnitude = allheads["score"][i] - getPlayerSize() -- could be changed to a constant value
local KnockbackMagnitude = 70
-- function below knocks the player off his feet
-- remove if you dont want that
--[[task.spawn(function()
local Humanoid = Character.Humanoid
Humanoid.PlatformStand = false
task.wait(0.5) -- time to wait before getting up
Humanoid.PlatformStand = true
end)]]
-- applying knockback
hrp.AssemblyLinearVelocity = KnockbackDirection * KnockbackMagnitude
end
end
end