Hello.
I was working on a game that I am getting paid for, and I have ran into an issue here.
I am developing a giant, that launches players into the air, and then eats them.
Game Link: Map - Roblox
GIANT
The problem is, that when the player gets eaten while he has just spawned, and is immune, then he will not be eaten again.
I think, that the problem has something to do with the distance checking:
Distance normally, when close to giant:
60
59
58
50
Distance after trying to be eaten, when close to giant:
80
70
68
60
Main Script
local humanoid = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("UpperTorso")
local animate = require(script.Parent.Animate)
local jump = false
local killedPlayers = {}
local function jump()
if not jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
jump = true
humanoid.StateChanged:Wait()
jump = false
end
end
local function closestPlayer()
local distances = {}
local lowest = math.huge
local player
for _, player in pairs(game.Players:GetPlayers()) do
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid and humanoid.Health > 0 then
distances[player] = player:DistanceFromCharacter(torso.Position)
end
end
for i, v in pairs(distances) do
if v and v < lowest then
lowest = i
end
end
for i, v in pairs(distances) do
if v and v == distances[lowest] then
player = i
end
end
if player then return player.Character:FindFirstChild("HumanoidRootPart"), distances[player] end
end
while true do
local root, distance = closestPlayer()
if root and distance then
humanoid:MoveTo(root.Position)
if distance <= 45 then
animate.stompAnimation(root)
humanoid:MoveTo(torso.Position)
task.wait(4.1)
end
animate.runAnimation()
else
humanoid:MoveTo(torso.Position)
end
task.wait()
end