Local scripts tend to load before the character does. To get by this you'll need to wait for any instances you're defining.
You should also properly acquire services when using any using the GetService() method.
To properly wait for the character (Instead of relying on a repeat loop), use CharacterAdded:Wait(). This Wait() function is called until the character loads which will then return it to us.
local Players = game:GetService("Players")
local p = Players.LocalPlayer
local c = p.Character or p.CharacterAdded:Wait()
local partTouch = workspace:WaitForChild("PinesBiome")
Notice how we define a variable that waits for the "PinesBiome" part? We need to make sure the part loads in so we can bind our events.
Debounces serve as on/off switches to make sure that events are not constantly firing.
####Currently your code looks like this:
if debounce == false then
debounce = true
workspace.PinesBiome.Touched:Connect(function()
end)
You have no end to close the if-statement but that's an easy problem to fix. The main issue I want to address is that you're checking the debounce BEFORE setting up your Touched events. This will run only once and never check for debounce again!
To fix this, place an if-statement into each Touched/TouchedEnded event with their own debounce. That way neither event interferes and no event is being spammed.
local debounce1 = true
local debounce2 = true
partTouch.Touched:Connect(function()
if debounce1 then
debounce1 = false
debounce1 = true
end
end)
partTouch.TouchEnded:Connect(function()
if debounce2 then
debounce2 = false
debounce2 = true
end
end)
Finally we need another switch so that both events know that the player is inside. This bool variable serves to check that if the player is inside then run code which reverts that ColorCorrection you are using. I had simply named it inside.
You also edit the ColorCorrection properties in a weird way. When you use a numerical for-loop, you should take advantage of the variable which shows the iteration it's on. Since you want to achieve a darkening effect you would do it on the ColorCorrection.Brightness property.
camera.correct.TintColor = Color3.fromRGB(125,143,123)
for i = 0, -.1, -.01 do
camera.correct.Brightness = i
wait()
end
The Brightness property for the ColorCorrection object works in a way where anything below 0 makes the lighting darker. So we need a loop that counts down. Toy with the values I had given above to get a proper look.
In our TouchEnded event we could revert all this back to normal by making sure that the player was inside with our inside bool variable.
if inside then
inside = false
camera.correct.TintColor = Color3.fromRGB(255,255,255)
camera.correct.Brightness = 0
end
####Your final code should look like:
local p = game.Players.LocalPlayer
local c = p.Character or p.CharacterAdded:Wait()
local camera = workspace.CurrentCamera
local debounce1 = true
local debounce2 = true
local inside = false
local partTouch = workspace:WaitForChild("PinesBiome")
partTouch.Touched:Connect(function()
if debounce1 then
debounce1 = false
if inside == false then
inside = true
p.PlayerGui.ScreenGui.Biome.Text = "Pines"
p.PlayerGui.ScreenGui.Biome.Dropshadow.Text = "Pines"
camera.correct.TintColor = Color3.fromRGB(125,143,123)
for i = 0, -.1, -.01 do
camera.correct.Brightness = i
wait()
end
end
debounce1 = true
end
end)
partTouch.TouchEnded:Connect(function()
if debounce2 then
debounce2 = false
if inside then
inside = false
camera.correct.TintColor = Color3.fromRGB(255,255,255)
camera.correct.Brightness = 0
end
debounce2 = true
end
end)
#####If I missed something then reply back with a comment or if there are any concerns with my explanations.
4 comments
use local variables & try not to use "repeat wait() until". "local c = p:WaitForChild("Character")" works just fine
Debounces are wrong too
U cant just say the script broke u have to rewrite ur debounces lol?
^^^ I did, and I tried the old script and it still doesn't work.