#Zone script wont work
137 messages · Page 1 of 1 (latest)
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()
thats fine, you can do it whenever. im going tobed anyways lol
appreciate it
oh ill google it then
I told to put print before the if-statement.
i did at some point iirc
I think it'd better to use getpartsinpart than anything else
print Players:GetPlayerFromCharacter•••
i assume the getpartsinparts would find the player if theyre within the area block?
I never used it. Can you hook an event to that?
Yes basically you can loop thru all the parts that are inside / touching the part
ok going to sleep fr before i genuinely pass out ill look into satuff tomorow, gn
Bell rang gtg bye
🪦
i wish
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
I am impressed with the code, I didn't expect this from you. I seen you talk about this in #📜︱scripting, did they do this? .-.
Message deleted.
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. .-.
yeah Ziffix gave me a hand with tidying it up
maybe thats it? ill try it
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"
yeah man, no idea whats wrong with it still
you know how in rogue lineage, deepwoken, etc the atmosphere and stuff changes based on location? im doing that with time of day for lighting purposes
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
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
the regions dont operate by being constantly in them, its when you pass a "barrier" if that makes any sense
it does...
that's your problem then
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
its a script drawing from a module inside the player
for performance i might make the check every, idk, 5 seconds?
you can do faster than that
also whats an include filter i cant find any good info about it 😭
you can do it on physics stepped even
local params = OverlapParams.new()
params.FilterType = Enum.FilterType.Include
params.FilterDescendantsInstances = {player.Character}
like this
can you give me an example of it being used? i dont really understand how id format it
local results = workspace:FindPartBoundsInBox(regionCFrame, regionSize, params)
might be cframe then size
i dont remember
13:19:54.816 FilterType is not a valid member of "Enum" - Server - ZoneGrab:10
might be raycastfiltertype
it is
so id change the code to local params = RaycastParams.new() ?
no
its still overlap params
but the filtertype uses raycast enum
i know its confusing
so raycast.filtertype instead of enum.filter>?
no
local params = OverlapParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = {player.Character}
local results = workspace:FindPartBoundsInBox(regionCFrame, regionSize, params)
exactly like that
im sorry i dont know what to do with regionCFrame
or region size
also 14:41:27.078 FindPartBoundsInBox is not a valid member of Workspace "Workspace" - Server - ZoneGrab:13
I do from memory you gotta look for the right one
kk
oh
its :GetPartBoundsInBox
yeah dont worry i figured that one on my own, but im still struggling with the regionCFrame
just needs to be a position
as if your region was a part
it would be the middle of it
as a cframe
whats an easy way to determine positions?
part.CFrame
part.Size
except
they don't actually need to exist
so
yeah it trakcs the space, thats whatim getting
doesnt make a part but it racks the space
tracks rather
local region = {cf = part.CFrame, size = part.Size}
part:Destroy()
local results = workspace:FindPartBoundsInBox(region.cf, region.size, params)
so if ium reading this right
this makes it so it gets the region from the part, stores the value then fucking vaporizes itself?
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
oops
still not working
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)
you gotta be doing it on loop
i have a loop below
do i gotta loop the entire script?
you gotta loop the getpartboundsinbox
isnt that just a variable? do i put the variable in the loop?
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
it doesnt bro ive been doing this for 5 days ;-;
where do i put that code
kk ty
ohhhh ill need to make a table for this i think
@woven verge i make the table in another script right
you don't have to
like, make the table or make the table in another script?
make it in another script