You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? I want the script (located in workspace) to receive the BindableEvent.
-
What is the issue? The BindableEvent is not being received or registered (see bottom of code). None of the print statements are firing.
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local ServerStorage = game:GetService('ServerStorage')
local corner1 = Vector3.new(script.Parent.Position + (script.Parent.Size/2)) -- Replace x1, y1, z1 with actual coordinates
local corner2 = Vector3.new(script.Parent.Position - (script.Parent.Size/2)) -- Replace x1, y1, z1 with actual coordinates
local ballDetectionRegion = Region3.new(corner1, corner2)
local runningThread = nil
-- Reference to the ball
local ball = workspace:WaitForChild("SoccerBall")
-- Predetermined function to be called
function onBallDetected()
print("Scored!!")
end
-- Function to check if the ball is inside the Region3
function isBallTouching(ball : BasePart, targetChar)
if not(targetChar) then
return
end
ball.Touched:Connect(function(hit)
if hit.Parent == targetChar then
return true
end
end)
return false
end
function storage(ball)
local overlaparams = OverlapParams.new()
local parts = workspace:GetPartBoundsInBox(CFrame.new(script.Parent.Position), script.Parent.Size, overlaparams)
return (table.find(parts, ball) ~= nil)
end
function onReset()
print('onreset called')
while true do
if storage(ball) == true then
onBallDetected(ball.PlayerWhoLastHit.Value)
break -- Stop the loop once the ball is detected inside the Region3
end
task.wait(0.05) -- Check periodically (adjust the interval as needed)
end
end
ReplicatedStorage.Bindables:WaitForChild("NewRoundBindable").Event:Connect(function()
print("EZPZ")
if (runningThread) then
coroutine.yield(runningThread)
end
runningThread = coroutine.create(function(...)
print('coro ran')
onReset()
end)
print('coro ran 2')
coroutine.resume(runningThread)
end)
ReplicatedStorage.Bindables:WaitForChild("NewRoundBindable").Event:Connect(function()
task.wait(3.1) --Wait for the ball to get cleared
if (runningThread) then
coroutine.yield(runningThread)
end
runningThread = coroutine.create(function(...)
onReset()
end)
coroutine.resume(runningThread)
end)