Помоги, у меня не работает этот скрипт. Он находит игрока в радиусе и изменяет значение…
- User
Помоги, у меня не работает этот скрипт. Он находит игрока в радиусе и изменяет значение state (0 если вне зоны обнаружения, 1 если в зоне), но вот изменения значения не считывает: local Players = game:GetService("Players") local CollectionService = game:GetService("CollectionService") local AnimationsFolder = script.Parent.Animations local detectionRadius = 50 local function findPlayerInRadius(NPC, State) local npcPosition = NPC.PrimaryPart.Position for _, player in ipairs(Players:GetPlayers()) do if player.Character and player.Character.PrimaryPart then local distance = player:DistanceFromCharacter(npcPosition) if distance <= detectionRadius then State = 1 print(State) else State = 0 print(State) end end end end for _, Plant in ipairs(CollectionService:GetTagged("Chomper")) do local AnimationController = Plant.AnimationController local Animator = AnimationController.Animator local ChomperAnimations = AnimationsFolder.NPC_Chomper local Sleep = AnimationController:LoadAnimation(ChomperAnimations.Sleep) local Awake = AnimationController:LoadAnimation(ChomperAnimations.Awake) local State = Plant:GetAttribute("State") while wait(0.1) do findPlayerInRadius(Plant, State) end Plant:GetAttributeChangedSignal("State"):Connect(function() if State == 0 then print("Not in radius") elseif State == 1 then print("In radius") end end) end
- Assistant
Ваша проблема связана с тем, что скрипт не изменяет значение в объекте, а лишь изменяет локальную переменную в функции . Когда вы передаете переменную в функцию, она копируется, и изменения, внесенные в функцию, не отражаются на исходной переменной или атрибуте объекта.