Hello, I’m developing a game that kills the player when they don’t reach a certain area quickly enough.
The problem is that when I use this following script, it only outputs if the player is in the zone, not outside of it. When they’re outside of the region, it doesn’t run the kill script that I have as a remote event nor does it print Player was not found in region.
print("firing script")
local SoundRegionsWorkspace = game.Workspace:WaitForChild("SoundRegions")
local Found = false
local points = 0
local repStor = game:GetService("ReplicatedStorage")
local killRemote = repStor:WaitForChild("KillRemote") --Requires a RemoteEvent named "KillRemote" to be childed under ReplicatedStorage
local RegionBoolean = game.Workspace.Values.RegionBoolean
print("firing detect script")
while true do
print("firing loop")
for i, v in pairs(SoundRegionsWorkspace:GetChildren())do
print("firing pairs")
local region = Region3.new(v.Position - (v.Size/2),v.Position + (v.Size/2))
local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())
for _, part in pairs(parts)do
print("checking if they're in region")
-- Loop
if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
print("Player was found")
Found = true
else
Found = false
print("Player was not found in region")
if RegionBoolean.Value == 1 then
killRemote:FireServer()
end
end
end
end
wait(0.05)
end