скрипт на lua. Пишу себе скрипт, звуки пропадание клавиши и тд работает, НО ВОТ ПРОБЛЕМА
Снизу вы видите скрипт, я хотел бы узнать что в этом скрипте не так, что игрок должен идти до Pritag, но вместо того чтобы идти как задано по функции, он делает 1 шаг и останавливается, а мне нужно чтобы игрок в команде "exe" шёл до pritag, а не делал собственно 1 шаг и скрипт переставал работать (тафтология, да). МОЛЮ ПОМОГИТЕ РЕШИТЬ ЭТУ ПРОБЛЕМУ Я 5 ЧАС НЕ МОГУ ПОНЯТЬ ЧТО НЕ ТАК
local Pritag = script.Parent
local ProximityPrompt = Instance.new("ProximityPrompt", Pritag)
ProximityPrompt.ActionText = "Сыграть в автомат"
ProximityPrompt.ObjectText = "Play"
ProximityPrompt.KeyboardKeyCode = Enum.KeyCode.R
ProximityPrompt.MaxActivationDistance = 14
ProximityPrompt.HoldDuration = 5
local Players = game:GetService("Players")
local PathfindingService = game:GetService("PathfindingService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ControlBlockEvent = ReplicatedStorage:WaitForChild("ControlBlockEvent")
local ATTRACTRADIUS = 209
local WALKSPEEDDURINGATTRACT = 40
local successSound = Instance.new("Sound", Pritag)
successSound.SoundId = "rbxassetid://135586592656507"
local failSound = Instance.new("Sound", Pritag)
failSound.SoundId = "rbxassetid://136688819798889"
local Debounce = false
local cooldownActive = false
local Road1 = workspace:FindFirstChild("Road1")
local Road2 = workspace:FindFirstChild("Road2")
local function MoveToPosition(humanoid, humanoidRoot, destination)
local path = PathfindingService:CreatePath()
path:ComputeAsync(humanoidRoot.Position, destination)
if path.Status ~= Enum.PathStatus.Success then
return false
end
local waypoints = path:GetWaypoints()
for _, waypoint in ipairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid.Jump = true
end
humanoid:MoveTo(waypoint.Position)
local reached = humanoid.MoveToFinished:Wait()
if not reached then
return false
end
end
return true
end
local function MoveExeWithWaypoints(targetPlayer)
local character = targetPlayer.Character
if not character then return end
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid then return end
local humanoidRoot = character:FindFirstChild("HumanoidRootPart")
if not humanoidRoot then return end
local originalSpeed = humanoid.WalkSpeed
humanoid.WalkSpeed = WALKSPEEDDURINGATTRACT
local pritagPos = Pritag.Position
if Road1 and Road2 then
local distToPritag = (humanoidRoot.Position - pritagPos).Magnitude
local distToWaypoint1 = (humanoidRoot.Position - Road1.Position).Magnitude
if distToPritag <= distToWaypoint1 then
MoveToPosition(humanoid, humanoidRoot, pritagPos)
else
local success = MoveToPosition(humanoid, humanoidRoot, Road1.Position)
if not success then
humanoid.WalkSpeed = 43
return
end
success = MoveToPosition(humanoid, humanoidRoot, Road2.Position)
if not success then
humanoid.WalkSpeed = originalSpeed
return
end
MoveToPosition(humanoid, humanoidRoot, pritagPos)
end
else
MoveToPosition(humanoid, humanoidRoot, pritagPos)
end
humanoid.WalkSpeed = originalSpeed
end
local function IsPlayerInRange(targetPlayer)
local character = targetPlayer.Character
if character and character:FindFirstChild("HumanoidRootPart") then
return (character.HumanoidRootPart.Position - Pritag.Position).Magnitude <= ATTRACTRADIUS
end
return false
end
local function OnPromptTriggered(player)
if Debounce or cooldownActive then return end
local teamName = player.Team and player.Team.Name or ""
if teamName ~= "Survivors" then return end
Debounce = true
ProximityPrompt.Enabled = false
if math.random() <= 0.8 then
successSound:Play()
local targetExe = nil
for _, p in pairs(Players:GetPlayers()) do
if p.Team and p.Team.Name == "Exe" and p.Character and p.Character:FindFirstChild("HumanoidRootPart") and IsPlayerInRange(p) then
targetExe = p
break
end
end
if targetExe then
ControlBlockEvent:FireClient(targetExe, true)
local touchedConnection
local reachedFlag = false
touchedConnection = Pritag.Touched:Connect(function(hit)
if hit.Parent == targetExe.Character then
reachedFlag = true
ControlBlockEvent:FireClient(targetExe, false)
if touchedConnection then
touchedConnection:Disconnect()
touchedConnection = nil
end
end
end)
MoveExeWithWaypoints(targetExe)
wait(6)
if not reachedFlag then
ControlBlockEvent:FireClient(targetExe, false)
if touchedConnection then
touchedConnection:Disconnect()
touchedConnection = nil
end
end
end
else
failSound:Play()
end
cooldownActive = true
cooldownActive = false
Debounce = false
end
ProximityPrompt.Triggered:Connect(OnPromptTriggered)
(P.S Извиняюсь что в пространства добавил Python, просто lua нет в нём, а питон самый близкий к нему)
local function MoveExeWithWaypoints(targetPlayer)
local character = targetPlayer.Character
if not character then return end
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid then return end
local humanoidRoot = character:FindFirstChild("HumanoidRootPart")
if not humanoidRoot then return end
local originalSpeed = humanoid.WalkSpeed
humanoid.WalkSpeed = WALKSPEEDDURINGATTRACT
-- Создаем BodyPosition для принудительного движения
local bodyPosition = Instance.new("BodyPosition")
bodyPosition.MaxForce = Vector3.new(4000, 0, 4000)
bodyPosition.P = 3000
bodyPosition.D = 500
bodyPosition.Parent = humanoidRoot
local pritagPos = Pritag.Position
-- Функция для движения к точке
local function moveToPoint(targetPos)
bodyPosition.Position = Vector3.new(targetPos.X, humanoidRoot.Position.Y, targetPos.Z)
-- Ждем пока игрок достигнет точки
repeat
wait(0.1)
local distance = ((humanoidRoot.Position - targetPos) * Vector3.new(1, 0, 1)).Magnitude
until distance < 3
end
-- Определяем маршрут
if Road1 and Road2 then
local distToPritag = (humanoidRoot.Position - pritagPos).Magnitude
local distToWaypoint1 = (humanoidRoot.Position - Road1.Position).Magnitude
if distToPritag <= distToWaypoint1 then
moveToPoint(pritagPos)
else
moveToPoint(Road1.Position)
moveToPoint(Road2.Position)
moveToPoint(pritagPos)
end
else
moveToPoint(pritagPos)
end
-- Удаляем BodyPosition и восстанавливаем скорость
bodyPosition:Destroy()
humanoid.WalkSpeed = originalSpeed
end