Atmosphere isent destroying for one player and not giving any error [SOLVED]

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:
Workspace
StarterPlayerScripts:
sps
New Locations:
Replicated:
RS
StarterScript:
sps

I would move the local script into plrStarterScripts for a start. Add some prints to see what’s running and what is not.

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

sorry, That was for another script simular. I will fix my error.

The local script is in replicated storage. I put it in there so i dont have to find the player and the event.

yep that’s why it’s not working

it won’t work if its in replicated storage put it in starterplayerscripts

When you add a local script there’s a list of the places where local scripts works starter player scripts is one of them

I changed the script that activeates the event 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

can you please tell me what the error says

The error saids: "PlayerScripts is not a valid member of Player “Players.thebeeninja5000” Even tho PlayerScripts is a member of my player.

playerscripts is not mentioned anywhere in the code you sent
nvm its in line 4 i didnt see it because you said line 6

i’m not sure why you’re getting the error but i have no idea why you’re putting the atmosphere folder in playerscripts

Non local script :

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


If there is any type of error please let me know

Ill try this soon! but the reason i put the things into a folder is so that i can toggle it using a boolen.

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!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.