JIT
fixing issues in your roblox script for player interaction and functionality
يعاني هذه سكربت من بعض مشاكل اول اذا لاعب اطفئه لا يعمل بعد الان وايضا اذا وصل الي 100 لا يتقل لاعب ويتقف عن عمل وهذه سكربت --[[ الوصف: هذا السكربت يوضع داخل جزء (Part) معين في Workspace. يقوم بإظهار BillboardGui فوق هذا الجزء بشكل دوري. يبدأ بنسبة 0% ثم تزداد النسبة بشكل عشوائي بعد فترة. يتغير لون النسبة بناءً على قيمتها. إذا وصلت النسبة إلى 100%، يموت اللاعب الذي قام بتفعيل الموجه آخر مرة. يمكن للاعبين إيقاف العملية عن طريق الضغط على زر 'E' عبر ProximityPrompt الموجود على الجزء، مما يؤدي إلى تناقص النسبة تدريجياً. المكان: يجب وضع هذا السكربت مباشرة داخل الجزء (Part) المستهدف. ]] -- خدمات local Players = game:GetService("Players") local Workspace = game:GetService("Workspace") -- الجزء المستهدف (هو الأب لهذا السكربت) local targetPart = script.Parent if not targetPart:IsA("BasePart") then warn("السكربت يجب أن يكون داخل كائن من نوع BasePart (مثل Part أو MeshPart)") script:Destroy() return end -- إعدادات (بالقيم التي قدمتها سابقًا) local MIN_INTERVAL = 1 local MAX_INTERVAL = 3 local MIN_ACTIVATION_DELAY = 1 local MAX_ACTIVATION_DELAY = 1 local PERCENT_INCREASE_RATE = 0.7 local PERCENT_INCREASE_AMOUNT = 5 local PERCENT_DECREASE_RATE = 2 local PERCENT_DECREASE_AMOUNT = 5 local YELLOW_THRESHOLD = 50 local RED_THRESHOLD = 80 local SOUND_ID = "rbxassetid://9117305275" -- !!! استبدل هذا بالـ ID الخاص بالصوت !!! local PROMPT_KEY = Enum.KeyCode.E local PROMPT_TEXT = "إطفاء النظام" -- متغيرات لتتبع حالة النظام (مرتبطة بالجزء) local currentPercentage = 0 local systemActive = false local decreasing = false local guiInstance = nil local soundInstance = nil local promptInstance = nil local mainCoroutine = nil local lastInteractorHumanoid = nil -- لتتبع اللاعب الذي يجب قتله -- دالة لتحديث واجهة المستخدم الرسومية local function updateGui() if guiInstance and guiInstance.Parent then local textLabel = guiInstance:FindFirstChild("PercentageLabel") if textLabel then textLabel.Text = tostring(math.floor(currentPercentage)) .. "%" if currentPercentage >= RED_THRESHOLD then textLabel.TextColor3 = Color3.fromRGB(255, 0, 0) -- أحمر elseif currentPercentage >= YELLOW_THRESHOLD then textLabel.TextColor3 = Color3.fromRGB(255, 255, 0) -- أصفر else textLabel.TextColor3 = Color3.fromRGB(255, 255, 255) -- أبيض end end end end -- دالة لتنظيف الموارد local function cleanup() print("Cleanup called for part: " .. targetPart.Name) -- DEBUG systemActive = false decreasing = false currentPercentage = 0 lastInteractorHumanoid = nil -- مسح اللاعب المستهدف عند التنظيف if soundInstance then soundInstance:Stop() soundInstance:Destroy() soundInstance = nil end if promptInstance then -- لا ندمر الموجه تماما إذا أردناه أن يظهر مجددا, فقط نعطله ونخفيه مؤقتا promptInstance.Enabled = false -- promptInstance:Destroy() -- يمكن إلغاء التعليق إذا أردت تدميره وإعادة إنشائه كل مرة end if guiInstance then guiInstance:Destroy() guiInstance = nil end -- إلغاء الكوروتين إذا كان يعمل if mainCoroutine and coroutine.status(mainCoroutine) ~= "dead" then task.cancel(mainCoroutine) -- الطريقة الأحدث لمحاولة الإلغاء mainCoroutine = nil end print("System cleanup finished for part: " .. targetPart.Name) -- DEBUG end -- دالة لإنشاء الواجهة الصوت والموجه local function createComponents() print("Attempting to create components...") -- DEBUG -- إنشاء BillboardGui guiInstance = Instance.new("BillboardGui") guiInstance.Name = "SystemStatusGui" guiInstance.Adornee = targetPart -- *** تغيير: الهدف هو الجزء نفسه *** guiInstance.Size = UDim2.new(4, 0, 1.5, 0) -- يمكن تعديل الحجم -- تعديل الارتفاع فوق الجزء، يعتمد على حجم الجزء local partHeight = targetPart.Size.Y guiInstance.StudsOffsetWorldSpace = Vector3.new(0, partHeight / 2 + 1.5, 0) guiInstance.AlwaysOnTop = true guiInstance.Enabled = true local textLabel = Instance.new("TextLabel") textLabel.Name = "PercentageLabel" textLabel.BackgroundTransparency = 1 textLabel.Size = UDim2.new(1, 0, 1, 0) textLabel.Font = Enum.Font.SourceSansBold textLabel.TextSize = 24 -- يمكن تعديل حجم الخط textLabel.TextColor3 = Color3.fromRGB(255, 255, 255) textLabel.Text = "0%" textLabel.Parent = guiInstance guiInstance.Parent = targetPart -- *** تغيير: إرفاق الواجهة بالجزء *** -- إنشاء الصوت print("Creating Sound Instance...") -- DEBUG soundInstance = Instance.new("Sound") soundInstance.SoundId = SOUND_ID soundInstance.Volume = 0.8 soundInstance.Looped = true soundInstance.Parent = targetPart -- *** تغيير: إرفاق الصوت بالجزء *** print("Sound Instance Created. SoundId: " .. soundInstance.SoundId) -- DEBUG -- إنشاء أو إعادة استخدام ProximityPrompt if not promptInstance or not promptInstance.Parent then print("Creating ProximityPrompt...") -- DEBUG promptInstance = Instance.new("ProximityPrompt") promptInstance.Name = "StopSystemPrompt" promptInstance.ObjectText = "النظام" promptInstance.ActionText = PROMPT_TEXT promptInstance.KeyboardKeyCode = PROMPT_KEY promptInstance.HoldDuration = 0 promptInstance.RequiresLineOfSight = false promptInstance.MaxActivationDistance = 15 -- تعديل مسافة التفعيل promptInstance.Parent = targetPart -- *** تغيير: إرفاقه بالجزء *** promptInstance.Triggered:Connect(function(triggeredPlayer) print("Prompt Triggered by: "..triggeredPlayer.Name) -- DEBUG if systemActive and not decreasing then local character = triggeredPlayer.Character if character then local humanoid = character:FindFirstChildOfClass("Humanoid") if humanoid and humanoid.Health > 0 then lastInteractorHumanoid = humanoid -- *** تخزين اللاعب المتفاعل *** print("Last interactor set to: " .. triggeredPlayer.Name) -- DEBUG end end systemActive = false decreasing = true if soundInstance then print("Stopping sound via prompt."); soundInstance:Stop() end -- DEBUG if promptInstance then promptInstance.Enabled = false end -- بدء عملية النقصان while currentPercentage > 0 and decreasing and targetPart and targetPart.Parent do print("Decreasing percentage...") -- DEBUG task.wait(PERCENT_DECREASE_RATE) if not decreasing or not targetPart or not targetPart.Parent then break end currentPercentage = math.max(0, currentPercentage - PERCENT_DECREASE_AMOUNT) updateGui() end -- إذا وصل للصفر أو توقف لسبب آخر if currentPercentage <= 0 then print("System deactivated by player via prompt.") -- DEBUG decreasing = false cleanup() -- ننظف تمامًا بعد الانتهاء -- إعادة جدولة الدورة التالية task.wait(math.random(MIN_INTERVAL, MAX_INTERVAL)) -- انتظار قبل البدء مجددًا if targetPart and targetPart.Parent and (not mainCoroutine or coroutine.status(mainCoroutine) == "dead") then print("Restarting cycle after prompt deactivation...") -- DEBUG mainCoroutine = coroutine.create(startSystemCycle) coroutine.resume(mainCoroutine) end else -- توقف النقصان لسبب آخر (مثل تدمير الجزء) decreasing = false -- إعادة تعيين الحالة print("Decrease interrupted.") -- DEBUG cleanup() -- تنظيف في حالة التوقف غير الطبيعي end end end) print("ProximityPrompt created and connected.") -- DEBUG end -- تفعيل الموجه في البداية (سيكون معطلاً أثناء الزيادة الفعلية) promptInstance.Enabled = false -- يبدأ معطلاً، يتم تفعيله عند بدء الزيادة updateGui() -- تحديث الواجهة لعرض 0% الأولية print("Components created successfully.") -- DEBUG end -- الدالة التي تدير دورة النظام بأكملها (مع آخر تعديلات التشخيص) local function startSystemCycle() print("startSystemCycle coroutine started.") -- DEBUG while targetPart and targetPart.Parent do print("Starting new cycle loop.") -- DEBUG -- >> فحص إضافي هنا << if not targetPart or not targetPart.Parent then print("ERROR: targetPart or its Parent became nil just before calculating wait!") -- DEBUG break -- اخرج من الحلقة إذا حدث هذا end print("DEBUG: Part Check OK before wait. Name: "..targetPart.Name..", Parent: "..targetPart.Parent.Name) -- DEBUG -- >> تبسيط مؤقت لـ math.random << local initialWait = 2 -- استخدم قيمة ثابتة مؤقتًا بدلًا من math.random(MIN_INTERVAL, MAX_INTERVAL) print("Waiting for initial interval (fixed): " .. initialWait .. "s") -- DEBUG task.wait(initialWait) -- >> استعادة الكود الأصلي بعد التأكد من عمله << -- local initialWait = math.random(MIN_INTERVAL, MAX_INTERVAL) -- print("Waiting for initial interval: " .. initialWait .. "s") -- DEBUG -- task.wait(initialWait) if not targetPart or not targetPart.Parent then print("Part removed during initial wait."); break end -- تحقق بعد الانتظار -- 2. إنشاء وإظهار الواجهة والمكونات الأخرى print("Calling createComponents...") -- DEBUG createComponents() if not guiInstance or not soundInstance or not promptInstance then warn("Failed to create components after call for part '".. targetPart.Name .."'") cleanup() break end print("createComponents finished.") -- DEBUG systemActive = false decreasing = false currentPercentage = 0 lastInteractorHumanoid = nil updateGui() -- Update to show 0% -- 3. فترة الانتظار قبل بدء زيادة النسبة local activationDelay = math.random(MIN_ACTIVATION_DELAY, MAX_ACTIVATION_DELAY) print("Waiting for activation delay: " .. activationDelay .. "s") -- DEBUG task.wait(activationDelay) if not targetPart or not targetPart.Parent then print("Part removed during activation delay."); cleanup(); break end if decreasing then print("Cycle interrupted before activation."); cleanup(); continue end -- 4. بدء زيادة النسبة وتشغيل الصوت وتفعيل الموجه print("Activating system: Playing sound and enabling prompt.") -- DEBUG systemActive = true decreasing = false if soundInstance then print("Attempting to play sound...") -- DEBUG -- استخدام pcall للتحقق من أخطاء تشغيل الصوت local success, err = pcall(function() soundInstance:Play() end) if not success then warn("Error playing sound: "..tostring(err)) end end if promptInstance then promptInstance.Enabled = true end -- 5. حلقة زيادة النسبة print("Starting increase loop.") -- DEBUG while systemActive and currentPercentage < 100 and targetPart and targetPart.Parent do print("Increase loop tick. Current Percentage: "..currentPercentage) -- DEBUG local waitTime = task.wait(PERCENT_INCREASE_RATE) if not systemActive or not targetPart or not targetPart.Parent then print("Exiting increase loop due to state change or part removal."); break end currentPercentage = currentPercentage + PERCENT_INCREASE_AMOUNT updateGui() -- 6. التحقق من الوصول إلى 100% if currentPercentage >= 100 then print("Reached 100%.") -- DEBUG systemActive = false if lastInteractorHumanoid and lastInteractorHumanoid.Parent and lastInteractorHumanoid.Health > 0 then print("Killing last interactor: " .. lastInteractorHumanoid.Parent.Name) -- DEBUG lastInteractorHumanoid.Health = 0 -- *** قتل اللاعب المتفاعل آخر مرة *** else print("No valid last interactor to kill.") -- DEBUG end cleanup() -- تنظيف الموارد print("Waiting before starting next cycle after 100%.") -- DEBUG task.wait(math.random(MIN_INTERVAL, MAX_INTERVAL)) break -- الخروج من حلقة الزيادة، الحلقة while الخارجية ستبدأ من جديد end end print("Exited increase loop.") -- DEBUG -- التعامل مع نهاية الدورة if not systemActive and decreasing then print("Increase loop ended, decrease started by prompt.") -- حلقة النقصان تتم معالجتها في حدث Triggered -- انتظر هنا حتى تنتهي عملية النقصان أو يتم تدمير الجزء while decreasing and targetPart and targetPart.Parent do task.wait(0.5) end print("Waited for decrease/part removal after prompt.") -- إذا انتهى النقصان بنجاح، سيتم التنظيف وبدء دورة جديدة بواسطة Triggered -- إذا تم تدمير الجزء، ستكتشف الحلقة while الخارجية ذلك elseif not systemActive and not decreasing and currentPercentage < 100 then -- توقفت لسبب آخر (مثل تدمير الجزء أثناء الزيادة) print("Increase loop stopped unexpectedly.") cleanup() break -- اخرج من الحلقة الرئيسية إذا توقفت بشكل غير طبيعي end print("End of cycle loop iteration.") -- DEBUG end -- نهاية الحلقة الرئيسية while print("System cycle stopped definitely for part '".. targetPart.Name .."' (Part removed or error).") -- DEBUG cleanup() -- تأكد من التنظيف عند الخروج النهائي end -- التعامل مع تدمير الجزء targetPart.Destroying:Connect(function() print("Part '".. targetPart.Name .."' is being destroyed. Cleaning up.") -- DEBUG cleanup() end) -- بدء الدورة الأولى للنظام if targetPart and targetPart.Parent then -- إضافة تأخير بسيط قبل البدء للتأكد من تحميل كل شيء task.wait(1) print("Starting initial system cycle coroutine for part: " .. targetPart.Name) -- DEBUG mainCoroutine = coroutine.create(startSystemCycle) coroutine.resume(mainCoroutine) else warn("Target part is invalid or already removed before script start.") end وهذه view في output ١٦:١١:٥٧.٤٠١ Starting initial system cycle coroutine for part: Part - Server - Script:332 ١٦:١١:٥٧.٤٠١ startSystemCycle coroutine started. - Server - Script:208

سأقوم بإصلاح المشكلات في السكربت. إليك النسخة المعدلة:

التغييرات الرئيسية التي قمت بها:

  1. إضافة متغير lastInteractorPlayer لتتبع اللاعب الذي تفاعل مع النظام
  2. استخدام task.spawn بدلاً من coroutine.create لتحسين الأداء
  3. تحسين عملية قتل اللاعب عند الوصول لـ100% للتحقق من وجود اللاعب أولاً
  4. تبسيط كود التنظيف وإزالة رسائل التصحيح
  5. تحسين إدارة حالات النظام عند الإطفاء
  6. إصلاح مشكلة عدم توقف النظام عند الوصول لـ100%
  7. تحسين متابعة اللاعب الذي أطفأ النظام لضمان عمل النظام بشكل صحيح
Updated files
v1