#Zone script wont work

137 messages · Page 1 of 1 (latest)

eternal rampart
#

I have a script to make it so people see different skies and lighting when they touch a zone, but I cant get it to work. What it SHOULD do is make only the client that touched it see the sky as night. Thing is, I cant get it to activate

white bone
#

Okay so use getpartsinpart function and then to all the players, apply the thing. If there is a player that's not found in the part then that player will get the effect removed

#

I'm at school rn and internet is shit so I can't go on Google to send you a link to the documentation of the function

#

Just look up:
Roblox workspace:GetPartsInPart()

eternal rampart
#

thats fine, you can do it whenever. im going tobed anyways lol
appreciate it

#

oh ill google it then

tribal trail
#

I told to put print before the if-statement.

eternal rampart
white bone
tribal trail
#

print Players:GetPlayerFromCharacter•••

eternal rampart
#

i assume the getpartsinparts would find the player if theyre within the area block?

tribal trail
white bone
#

Yes basically you can loop thru all the parts that are inside / touching the part

eternal rampart
#

ok going to sleep fr before i genuinely pass out ill look into satuff tomorow, gn

white bone
#

Bell rang gtg bye

tribal trail
#

🪦

eternal rampart
#
local AtmoAlterModule = {}

local Player = game.Players.LocalPlayer
local Lighting = game.Lighting

function AtmoAlterModule.EnteredCave()
    Lighting.ClockTime = 0
    Lighting.Brightness = 0
    Lighting.GlobalShadows = false
end

function AtmoAlterModule.ExitCave()
    Lighting.ClockTime = 14.5
    Lighting.Brightness = 1
    Lighting.GlobalShadows = true
end

return AtmoAlterModule
#

when you touch the red, it runs this code which makes the screen darker

-- Makes the block invisible when the game starts.
script.Parent.Transparency = 1
-- Services
local Players = game:GetService("Players")
workspace:WaitForChild("CaveZoneBrick")
-- Variables
local Zone = workspace.CaveZoneBrick
local Atmo = require(game.StarterPlayer.StarterPlayerScripts:WaitForChild("AtmoAlterModule"))

-- Code
Zone.Touched:Connect(function(otherPart)
    local character = otherPart.Parent
    local humanoid = character:FindFirstChildOfClass("Humanoid")

    -- Check if a living entity is what collided with the zone
    if not humanoid or humanoid.Health == 0 then
        return
    end

    local player = Players:GetPlayerFromCharacter(character)

    -- Check if that entity is the LocalPlayer
    if not player or player ~= Players.LocalPlayer then
        return
    end

    Atmo.EnteredCave()
end)

when you touch the blue, it runs this code which returns it to normal

-- Makes the block invisible when the game starts.
script.Parent.Transparency = 1
-- Services
local Players = game:GetService("Players")
workspace:WaitForChild("OverworldZoneBrick")
-- Variables
local Zone = workspace.OverworldZoneBrick
local Atmo = require(game.StarterPlayer.StarterPlayerScripts:WaitForChild("AtmoAlterModule"))

-- Code
Zone.Touched:Connect(function(otherPart)
    local character = otherPart.Parent
    local humanoid = character:FindFirstChildOfClass("Humanoid")

    -- Check if a living entity is what collided with the zone
    if not humanoid or humanoid.Health == 0 then
        return
    end

    local player = Players:GetPlayerFromCharacter(character)

    -- Check if that entity is the LocalPlayer
    if not player or player ~= Players.LocalPlayer then
        return
    end

    Atmo.ExitCave()
end)

however, when i touch the red block then touch the blue block it stays dark

tribal trail
#

Everything except Light.ClockTime work, right? It might be that you did ClockTime wrong. I checked the documentions and it says it takes ClockTime as hours. Confused. .-.

eternal rampart
eternal rampart
tribal trail
#

Instead of doing this:

workspace:WaitForChild("CaveZoneBrick")
-- Variables
local Zone = workspace.CaveZoneBrick
```**You could just do:**
```lua
local Zone = workspace:WaitForChild("CaveZoneBrick")
#

You can change the time by doing:

Lighting.TimeOfDay = "14:30:00"
woven verge
#

suh dud

#

you still need help?

eternal rampart
woven verge
#

alright

#

what u tryna do

eternal rampart
woven verge
#

i see

#

what is your thinking to tackle the problem

eternal rampart
#

so the issue is in particular when you go into the cave, it works fine
but it cant switch back

there isnt any errors, so i have zero clue whats wrong with it

#

i dont really have a thinking to tackle the problem, because i have no leads and was hoping someone more experienced like you would have an idea

woven verge
#

alright

#

this is what you do

#

each frame you check each region to see if the player is in it

#

if the player is in a region find the region with the higher priority

#

then tween the lighting settings to a preset

eternal rampart
#

the regions dont operate by being constantly in them, its when you pass a "barrier" if that makes any sense

eternal rampart
woven verge
#

that's your problem then

eternal rampart
#

huh, alright

#

so check every frame if a palyers in them?

woven verge
#

the region part detecting the change isn't very reliable

#

yeah, use a include filter for the query and it shouldn't be too costly on performance

#

and even better if its localscript

#

because then you only need to check where the current player is

eternal rampart
#

its a script drawing from a module inside the player

#

for performance i might make the check every, idk, 5 seconds?

woven verge
#

you can do faster than that

eternal rampart
#

also whats an include filter i cant find any good info about it 😭

woven verge
#

you can do it on physics stepped even

#
local params = OverlapParams.new()
params.FilterType = Enum.FilterType.Include
params.FilterDescendantsInstances = {player.Character}
#

like this

eternal rampart
woven verge
#
local results = workspace:FindPartBoundsInBox(regionCFrame, regionSize, params)
#

might be cframe then size

#

i dont remember

eternal rampart
woven verge
#

might be raycastfiltertype

#

it is

eternal rampart
woven verge
#

no

#

its still overlap params

#

but the filtertype uses raycast enum

#

i know its confusing

eternal rampart
woven verge
#

no

#
local params = OverlapParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = {player.Character}

local results = workspace:FindPartBoundsInBox(regionCFrame, regionSize, params)
#

exactly like that

eternal rampart
#

or region size

#

also 14:41:27.078 FindPartBoundsInBox is not a valid member of Workspace "Workspace" - Server - ZoneGrab:13

woven verge
#

I do from memory you gotta look for the right one

eternal rampart
#

kk

woven verge
#

oh

#

its :GetPartBoundsInBox

eternal rampart
# woven verge oh

yeah dont worry i figured that one on my own, but im still struggling with the regionCFrame

woven verge
#

just needs to be a position

#

as if your region was a part

#

it would be the middle of it

#

as a cframe

eternal rampart
woven verge
#

part.Size

#

except

#

they don't actually need to exist

#

so

eternal rampart
#

yeah it trakcs the space, thats whatim getting

#

doesnt make a part but it racks the space

#

tracks rather

woven verge
#

local region = {cf = part.CFrame, size = part.Size}
part:Destroy()

local results = workspace:FindPartBoundsInBox(region.cf, region.size, params)

eternal rampart
#

so if ium reading this right
this makes it so it gets the region from the part, stores the value then fucking vaporizes itself?

woven verge
#

yep

#

more or less

eternal rampart
# woven verge more or less

16:46:52.106 Argument 2 missing or nil - Server - ZoneGrab:13
16:46:52.162 FindPartBoundsInBox is not a valid member of Workspace "Workspace" - Studio

woven verge
#

fuck

#

i meant get

#

same error lol

eternal rampart
#

oops

eternal rampart
#

let me get the rest of my code and u can tell me if something is janky as fuck

#
-- Makes the block invisible when the game starts.
script.Parent.Transparency = 1
-- Services
local Players = game:GetService("Players")
workspace:WaitForChild("CaveZoneBrick")
-- Variables
local Zone = workspace.CaveZoneBrick
local Atmo = require(game.StarterPlayer.StarterPlayerScripts:WaitForChild("AtmoAlterModule"))
local params = OverlapParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = {Players.LocalPlayer}
local region = {cf = Zone.CFrame, size = Zone.Size}
Zone:Destroy()

local results = workspace:GetPartBoundsInBox(region.cf, region.size, params)

-- Code
Zone.Touched:Connect(function(otherPart)
    local character = otherPart.Parent
    local humanoid = character:FindFirstChildOfClass("Humanoid")

    -- Check if a living entity is what collided with the zone
    if not humanoid or humanoid.Health == 0 then
        return
    end

    local player = Players:GetPlayerFromCharacter(character)

    -- Check if that entity is the LocalPlayer
    if not player or player ~= Players.LocalPlayer then
        return
    end
    print("A player has entered the region CaveZoneBrick.")
    if results == true then
        while true do
            Atmo.EnteredCave()
            wait(5)
            print("Ran a check of the region CaveZoneBrick due to player activity.")
        end
    end
end)

woven verge
#

you gotta be doing it on loop

eternal rampart
woven verge
#

you gotta loop the getpartboundsinbox

eternal rampart
#

isnt that just a variable? do i put the variable in the loop?

woven verge
#

yes

#

uh

#

i think

#

you worded that weirdly

#
local zones = {}

for _, part in workspace.ZoneParts:GetChildren() do
   table.insert(zones, {name = part:GetAttribute("ZoneType"), cf = part.CFrame, size = part.Size})
   part:Destroy()
end

local currentZone = nil
-- check loop
RunService.PostSimulation:Connect(function()
  -- get zones player is in
  local params = OverlapParams.new()
  params.FilterType = Enum.RaycastFilterType.Include
  params.FilterDescendantsInstances = {Players.LocalPlayer}

  -- check all zones to find out which they're in
  local foundZones = {}
  for _, zone in zones do
    -- check if player is in this zone
    local results = workspace:GetPartBoundsInBox(zone.cf, zone.size, params)
    if not results then continue end

    -- results were found
    table.insert(foundZones, zone)
  end
  
  -- you could do this smarter by priority or something but i'm just gonna pick at random
  local foundZone = foundZones[math.random(1, #foundZones)]

  -- if the zone found is the same one we already know they in don't change anything.
  if currentZone == foundZone.name then
    return
  end

  -- update current zone if its different
  currentZone = foundZone.name

  -- set the ambiance lighting and stuff according to the zone name
  SetAmbiance(foundZone.name)
end)
#

maybe this will make more sense

eternal rampart
#

where do i put that code

woven verge
#

READ IT

#

DO NOT COPY PASTE

#

WITHOUT UNDERSTAND

#

IT WILL NOT WORK OUT OF THE BOX

woven verge
#

i added some comments

#

so u can understand

eternal rampart
#

kk ty

#

ohhhh ill need to make a table for this i think

#

@woven verge i make the table in another script right

woven verge
#

you don't have to

eternal rampart
woven verge
#

make it in another script