I need to make it so that the atmosphere will delete when the player enter the caves (touched a part.)
The script is not destroying the atmosphere. Is it somthing to do with the remote event?
I tried everything I could think of and nothing worked.
Script that fires the remote event (Legacy) error at line 6 btw.
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
local AtmosphereFolder = plr.PlayerScripts.AtmosphereEdit
local Event = AtmosphereFolder.AtmosphereRemove
print(plr)
Event:FireClient(plr, script.Atmosphere)
end
end)
Script that removes it (Client)
script.Parent.OnClientEvent:Connect(function()
local Folder = script.Parent.Parent
if Folder.Atmosphere.Value == true then
local Atmos = game.Lighting.Atmosphere
Atmos:Destroy()
Folder.AtmosphereBool.Value = false
end
end)
Can somone tell me a fix to my
script? It would be awsome if you could find a correct fix with my script.
Edit: Some may wonder what instances im using. Heres 2 images. one in StarterPlayerScripts, and one in workspace.
Original Loacations:
workspace:
the position of the remote events and scripts is confusing me. and may i ask why you’re firing with the script.Atmosphere parameter if you’re not using it
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
local AtmosphereFolder = plr.PlayerScripts.AtmosphereEdit
local Event = AtmosphereFolder.AtmosphereRemove
print(plr)
Event:FireClient(plr, script.Atmosphere)
end
end)
But gives an error at line 6 and i dont understand
TouchingPart = script.Parent -- Change it to the part that gets touched by the player
Event = game:GetService("ReplicatedStorage").Event -- Change this to the event
TouchingPart.Touched:Connect(function(hit)
if hit:FindFirstAncestorOfClass("Model") and hit:FindFirstAncestorOfClass("Model"):FindFirstChildOfClass("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(hit:FindFirstAncestorOfClass("Model"))
print(plr:GetFullName()) -- more info
Event:FireClient(plr, "Atmosphere") -- Change to the name of the atmosphere to delete
else
error("Part hit : " .. hit:GetFullName())
end
end)
Local script :
local Lighting = game:GetService("Lighting")
local Event = script.Parent -- Change to the remotevent
-- Creating a folder to archive your atmospheres
local Folder = Instance.new("Folder")
Folder.Parent = Lighting
Folder.Name = "Archived"
--------
Event.OnClientEvent:Connect(function(AtmosphereName)
if Lighting:FindFirstChild(AtmosphereName) then
local Atmosphere = Lighting:FindFirstChild(AtmosphereName)
Atmosphere.Parent = Folder
else
error("Failed finding " .. AtmosphereName)
end
end)
Here is how i would do this : 1) Make a Atmosphere (or the one you are using) and place it to Lighting 2) Place the event into ReplicatedStorage 3) Place the Script in ServerScriptService or in the Part and the LocalScript in StarterGui
I had to edit 1 line because it (for some reason) wasent working (line 10) but after the fix the atmosphere deleted! (or just put inside a folder) but same thing. But thanks for helping!