function leafOnEarningArea()
for _, leaf in ipairs(leafFolder:GetChildren()) do
if leaf:IsA("BasePart") and leaf.Name == "Leaf" then
leaf.Touched:Connect(function(hit)
if hit == earningArea then
if debounce == false then
debounce = true
leafSuprresion.Value = leafSuprresion.Value - 1
leaf:Destroy()
getStat()
debounce = false
end
end
end)
end
end
end
function checkColisionWithBlower()
for _, leaf in ipairs(leafFolder:GetChildren()) do
if leaf:IsA("BasePart") and leaf.Name == "Leaf" then
leaf.Touched:Connect(function(hit)
if hit == blowerHitBox then
if debounce == false then
debounce = true
local direction = (leaf.Position - blowerHitBox.Position).Unit
leaf.AssemblyLinearVelocity = direction * 30 -- Expulse la feuille
task.wait(0)
debounce = false
end
end
end)
end
end
end
-- Recuper les stat du joueur au nécesaire et de les mettres à jours
function getStat()
local player = Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local stat = leaderstats:WaitForChild("Leaf")
task.wait(0)
stat.Value += 1
return
end
while true do
checkColisionWithBlower()
leafOnEarningArea()
task.wait(0) -- Boucle rapide
end
#Performance issue
31 messages · Page 1 of 1 (latest)
Use Collection service bro.
my idea is to learn how to code, every while loop you're connecting 2 .Touched event
collectionservice is mid 🙏
It works, cuh.
there is some use cases but almost always is gonna be a better sol
it works = its not the best
Then what's the better optino
and if you're going to make a project or game with the first thing that works lol
in this case for example a length for loop, to loop throught all leafs for example
depends on how is his game organised
is it possible to switch this around so that the blower is the one checking collision with leaves? (less touched connections)
exactly, every loop in the while hes connecting TWO connections of touched event, in js 1 second there can be already 40 connections
also from what i can gather all the leaves are all unanchored, is that correct? @rotund oasis
This is reasons
@terse musk and @frigid wind
And the spawn of a leaf is organise this way :
a
local leafSpawnArea = workspace.Area:WaitForChild("leafSpawnArea")
local maxLeaf = 30
local actualLeaf = Instance.new("IntValue")
actualLeaf.Name = "actualLeaf"
actualLeaf.Parent = game.Workspace:WaitForChild("leafFolderPart")
actualLeaf.Value = 0
function triggerRandomEvent()
local minX, maxX, minZ, maxZ = limiteOfSpawnArea()
local randomIndex = math.random(1, 3)
if randomIndex == 1 then
if actualLeaf.Value < maxLeaf then -
local leaf = Instance.new("Part")
leaf.Size = Vector3.new(1, 0.5, 1)
leaf.BrickColor = BrickColor.new("Tr. Green")
leaf.Anchored = false
leaf.Name = "Leaf"
leaf.CanCollide = true
local randomX = math.random(minX, maxX)
local randomZ = math.random(minZ, maxZ)
local yPosition = leafSpawnArea.Position.Y + 10
leaf.Position = Vector3.new(randomX, yPosition, randomZ)
leaf.Parent = workspace:WaitForChild("leafFolderPart")
actualLeaf.Value = actualLeaf.Value + 1
end
end
end
function limiteOfSpawnArea()
local leafSpawnAreaPosition = leafSpawnArea.Position
local leafSpawnAreaSize = leafSpawnArea.Size
local minX = (leafSpawnAreaPosition.X - leafSpawnAreaSize.X / 2) + 3
local maxX = (leafSpawnAreaPosition.X + leafSpawnAreaSize.X / 2) - 3
local minZ = (leafSpawnAreaPosition.Z - leafSpawnAreaSize.Z / 2) + 3
local maxZ = (leafSpawnAreaPosition.Z + leafSpawnAreaSize.Z / 2) - 3
return minX, maxX, minZ, maxZ
end
while true do
triggerRandomEvent()
wait(1)
end
when i finish a call ill explain how if someone didnt already
basically when u create a new leafe connect to it a .Touched event, just one for it
leaf.Touched
and there do the logic of givin the player the things and all that
** You are now Level 3! **
I will try to use an other event
quick idea
try having the leaves be anchored until they are interacted with to see if that might help the performance