You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to detect if a player has gone below -200 in the Y axis/vector3.Y without looping
What is the issue? Include screenshots / videos if possible!
No issues yet I just want optimization
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
It is easy to think about while waits and heartbeats though I don’t want those I want a more optimize solution maybe event based though I don’t know how I would go about it
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
--print("Thanks for feedback")
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
local Players = game:GetService("Players")
local function Check(plr : Player)
while task.wait() do
local Character = plr.Character or plr.CharacterAdded:Wait()
if Character then
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
if HumanoidRootPart then
local y = HumanoidRootPart.Position.Y
if y < -200 then
print(plr.DisplayName .. " is under -200")
end
end
end
end
end
local function PlayerAdded(plr : Player)
local Character = plr.Character or plr.CharacterAdded:Wait()
if not Character then
return warn("Character not found for " .. plr.Name)
end
task.spawn(function()
Check(plr)
end)
end
Players.PlayerAdded:Connect(PlayerAdded)
also task.wait() waits 1 frame so u don’t have to worry about lags because it only fires 60 times per second while true tries to fire infinity times in a second