Can someone fix up this script?

I need someone to fix this script, You can do anything, orginise it or something… I just want it to work like it shoud!

local WorkspaceService = game.Workspace
local Sound = false


local VolumeTo = {

	Volume = 1

}

local VolumeBack = {

	Volume = 0

}

local SoundTweenTo = game.TweenService:Create(script.HB, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), VolumeTo)

local SoundTweenBack = game.TweenService:Create(script.HB, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), VolumeBack)


function Raycast()
	
	local deb = false
	
	local camera = workspace.CurrentCamera
	local cameraCF = camera.CFrame

	local length = 1000
	local params = RaycastParams.new()
	
	local NumberTweenTo = {

		FieldOfView = 50

	}

	local NumberTweenBack = {

		FieldOfView = 70

	}
	
	
	
	
	local TintTo = {

		TintColor = Color3.fromRGB(255, 128, 128)

	}

	local TintBack = {

		TintColor = Color3.fromRGB(255, 255, 255)

	}
	
	local TintToTween = game.TweenService:Create(game.Lighting.ColorCorrection, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), TintTo)

	local TintBackTween = game.TweenService:Create(game.Lighting.ColorCorrection, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), TintBack)


	
	
	local MainTweenTo = game.TweenService:Create(game.Workspace.CurrentCamera, TweenInfo.new(4, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), NumberTweenTo)
	
	local MainTweenBack = game.TweenService:Create(game.Workspace.CurrentCamera, TweenInfo.new(2, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), NumberTweenBack)
	
	

	
	local raycastResult = workspace:Raycast(cameraCF.Position, cameraCF.LookVector * length, params)
	
	if raycastResult then
	
	if raycastResult.Instance then
		
			if raycastResult.Instance.Name == "TurnAroundPart" then
				
				if deb == false then
					
					deb = true
					
					MainTweenBack:Cancel()
					
					MainTweenTo:Play()
					
					wait(1.5)
					
					Sound = true
					
					SoundTweenTo:Play()
					
					wait(0.2)
					
					TintBackTween:Cancel()
					
					TintToTween:Play()
					
					wait(0.2)
					
					game.Lighting.ColorCorrection.Enabled = false
					
					game.Lighting.ColorCorrection2.Enabled = true
					
					wait(0.2)

					game.Lighting.ColorCorrection.Enabled = true

					game.Lighting.ColorCorrection2.Enabled = false
					
					wait(0.2)

					game.Lighting.ColorCorrection.Enabled = false

					game.Lighting.ColorCorrection2.Enabled = true
					
					wait(0.2)

					game.Lighting.ColorCorrection.Enabled = true

					game.Lighting.ColorCorrection2.Enabled = false
					
					wait(0.2)
					
					game.TweenService:Create(game.Lighting.ColorCorrection, TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0), {TintColor = Color3.fromRGB(49, 0, 0)
					}):Play()
					
				else
						
						Sound = false
						
					deb = false
					
					MainTweenTo:Cancel()

					MainTweenBack:Play()
					
					TintToTween:Cancel()
					
					TintBackTween:Play()

						
					end
					
			
				
			else
				

				
					deb = false
					
					Sound = false
				
				MainTweenTo:Cancel()
				
				MainTweenBack:Play()
				
				TintToTween:Cancel()

				TintBackTween:Play()
					
		
				
			end
			
		else
			

			
				deb = false
				
				Sound = false
			
			MainTweenTo:Cancel()
			
			MainTweenBack:Play()
			
			TintToTween:Cancel()

			TintBackTween:Play()

				
		
		
		end
		
		
	end
	
	
	
end


game["Run Service"].RenderStepped:Connect(function()
	
	if Sound == true then
		
		SoundTweenBack:Cancel()
		
		SoundTweenTo:Play()
		
		Raycast()
		
	else
		
		SoundTweenTo:Cancel()

		SoundTweenBack:Play()
		
		Raycast()

	end
	
end)

You should start by telling us what it is supposed to do, and what it is doing that is unexpected.

1 Like
local TweenService = game:GetService("TweenService")
local Workspace = game:GetService("Workspace")
local Lighting = game:GetService("Lighting")
local RunService = game:GetService("RunService")
local soundEnabled = false
local debounce = false
local camera = Workspace.CurrentCamera
local tweenInfoFast = TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
local tweenInfoSlow = TweenInfo.new(2, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
local cameraFOVTweenTo = TweenService:Create(camera, TweenInfo.new(4, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {FieldOfView = 50})
local cameraFOVTweenBack = TweenService:Create(camera, tweenInfoSlow, {FieldOfView = 70})
local soundTweenTo = TweenService:Create(script.HB, tweenInfoFast, {Volume = 1})
local soundTweenBack = TweenService:Create(script.HB, tweenInfoFast, {Volume = 0})
local tintTweenTo = TweenService:Create(Lighting.ColorCorrection, tweenInfoFast, {TintColor = Color3.fromRGB(255, 128, 128)})
local tintTweenBack = TweenService:Create(Lighting.ColorCorrection, tweenInfoFast, {TintColor = Color3.fromRGB(255, 255, 255)})

local function performRaycast()
    local raycastParams = RaycastParams.new()
    local raycastResult = Workspace:Raycast(camera.CFrame.Position, camera.CFrame.LookVector * 1000, raycastParams)

    if raycastResult and raycastResult.Instance and not debounce then
        debounce = true
        if raycastResult.Instance.Name == "TurnAroundPart" then
            cameraFOVTweenBack:Cancel()
            cameraFOVTweenTo:Play()
            soundEnabled = true
            soundTweenTo:Play()
            tintTweenBack:Cancel()
            tintTweenTo:Play()
            Lighting.ColorCorrection.Enabled = toggleEffect(Lighting.ColorCorrection.Enabled)
        else
            resetEffects()
        end
    elseif not raycastResult then
        resetEffects()
    end
end

local function toggleEffect(isEnabled)
    return not isEnabled
end

local function resetEffects()
    debounce = false
    soundEnabled = false
    cameraFOVTweenTo:Cancel()
    cameraFOVTweenBack:Play()
    tintTweenTo:Cancel()
    tintTweenBack:Play()
    soundTweenTo:Cancel()
    soundTweenBack:Play()
end

RunService.RenderStepped:Connect(function()
    if soundEnabled then
        soundTweenBack:Cancel()
        soundTweenTo:Play()
    else
        soundTweenTo:Cancel()
        soundTweenBack:Play()
    end
    performRaycast()
end)

1 Like

We’re not doing the work for you, thats not how it works.

2 Likes

We won’t and can’t help you if you don’t tell us what how this code is supposed to work and what is supposed to happen.

hey if it were me id just shove it into chatgpt, if it cant fix it it can prob tell you whats wrong

i forgor to say that, anyways the thingy like flickers and stuff and its messy and stuff, i didint know how to explain it, and i still dont know how

  1. This script controls camera movements and visual effects based on raycasting.
  2. Tween parameters are set for adjusting volume, camera field of view, and color tint.
  3. Raycasting is performed to detect certain parts in the workspace.
  4. If the raycast hits a part named “TurnAroundPart”, specific effects are triggered.
  5. Camera movements are controlled using tween animations.
  6. Color correction and sound volume adjustments are handled based on the raycast result.
  7. The script connects to the RenderStepped event to update effects and raycasting continuously.

Good Luck :smirk:

-- This script controls camera movements and visual effects based on raycasting.

local WorkspaceService = game.Workspace
local Sound = false

-- Tween parameters for adjusting volume
local VolumeTo = {
	Volume = 1
}

local VolumeBack = {
	Volume = 0
}

-- Tween animations for sound volume
local SoundTweenTo = game.TweenService:Create(script.HB, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), VolumeTo)
local SoundTweenBack = game.TweenService:Create(script.HB, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), VolumeBack)

-- Function to perform raycasting
function Raycast()
	local deb = false
	local camera = workspace.CurrentCamera
	local cameraCF = camera.CFrame
	local length = 1000
	local params = RaycastParams.new()

	-- Tween parameters for adjusting camera field of view
	local NumberTweenTo = {
		FieldOfView = 50
	}

	local NumberTweenBack = {
		FieldOfView = 70
	}

	-- Tween parameters for adjusting color tint
	local TintTo = {
		TintColor = Color3.fromRGB(255, 128, 128)
	}

	local TintBack = {
		TintColor = Color3.fromRGB(255, 255, 255)
	}
	
	-- Tween animations for color correction
	local TintToTween = game.TweenService:Create(game.Lighting.ColorCorrection, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), TintTo)
	local TintBackTween = game.TweenService:Create(game.Lighting.ColorCorrection, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), TintBack)

	-- Tween animations for camera field of view
	local MainTweenTo = game.TweenService:Create(game.Workspace.CurrentCamera, TweenInfo.new(4, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), NumberTweenTo)
	local MainTweenBack = game.TweenService:Create(game.Workspace.CurrentCamera, TweenInfo.new(2, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), NumberTweenBack)

	-- Perform raycast
	local raycastResult = workspace:Raycast(cameraCF.Position, cameraCF.LookVector * length, params)
	
	if raycastResult then
		if raycastResult.Instance then
			if raycastResult.Instance.Name == "TurnAroundPart" then
				if deb == false then
					deb = true
					MainTweenBack:Cancel()
					MainTweenTo:Play()
					wait(1.5)
					Sound = true
					SoundTweenTo:Play()
					wait(0.2)
					TintBackTween:Cancel()
					TintToTween:Play()
					wait(0.2)
					game.Lighting.ColorCorrection.Enabled = false
					game.Lighting.ColorCorrection2.Enabled = true
					wait(0.2)
					game.Lighting.ColorCorrection.Enabled = true
					game.Lighting.ColorCorrection2.Enabled = false
					wait(0.2)
					game.Lighting.ColorCorrection.Enabled = false
					game.Lighting.ColorCorrection2.Enabled = true
					wait(0.2)
					game.Lighting.ColorCorrection.Enabled = true
					game.Lighting.ColorCorrection2.Enabled = false
					wait(0.2)
					game.TweenService:Create(game.Lighting.ColorCorrection, TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0), {TintColor = Color3.fromRGB(49, 0, 0)}):Play()
				else
					Sound = false
					deb = false
					MainTweenTo:Cancel()
					MainTweenBack:Play()
					TintToTween:Cancel()
					TintBackTween:Play()
				end
			else
				deb = false
				Sound = false
				MainTweenTo:Cancel()
				MainTweenBack:Play()
				TintToTween:Cancel()
				TintBackTween:Play()
			end
		else
			deb = false
			Sound = false
			MainTweenTo:Cancel()
			MainTweenBack:Play()
			TintToTween:Cancel()
			TintBackTween:Play()
		end
	end
end

-- Connect to the RenderStepped event to update effects and raycast
game["Run Service"].RenderStepped:Connect(function()
	if Sound == true then
		SoundTweenBack:Cancel()
		SoundTweenTo:Play()
		Raycast()
	else
		SoundTweenTo:Cancel()
		SoundTweenBack:Play()
		Raycast()
	end
end)

Are you saying you don’t know what you want it to do? And you can’t explain what you expect it to do?

Let me help you start. So finish this sentence:

I’m trying to make a script that will…

It’s making me uncomfortable how much space is between everything.

Same. I’ve never seen that much spacing. Also, why did they use a table for each of the values… I feel like you could just use variables. Just specify sound.Volume = VolumeBack and VolumeBack = 0

I guess we should remember this dude is 11 though.

1 Like

Also, PLEASE use task.wait(), I don’t care if it’s not intended, you need to.

1 Like
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")

local camera = workspace.CurrentCamera

local VolumeTo = { Volume = 1 }
local VolumeBack = { Volume = 0 }

local SoundTweenTo = game.TweenService:Create(script.HB, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), VolumeTo)
local SoundTweenBack = game.TweenService:Create(script.HB, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), VolumeBack)

local Sound = false

local function Raycast()
	local deb = false
	local cameraCF = camera.CFrame

	local length = 1000
	local params = RaycastParams.new()

	local NumberTweenTo = { FieldOfView = 50 }
	local NumberTweenBack = { FieldOfView = 70 }
	local TintTo = ( TintColor = Color3.fromRGB(255, 128, 128) }
	local TintBack = { TintColor = Color3.fromRGB(255, 255, 255) }

	local TintToTween = game.TweenService:Create(game.Lighting.ColorCorrection, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), TintTo)
	local TintBackTween = game.TweenService:Create(game.Lighting.ColorCorrection, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), TintBack)
	local MainTweenTo = game.TweenService:Create(game.Workspace.CurrentCamera, TweenInfo.new(4, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), NumberTweenTo)
	local MainTweenBack = game.TweenService:Create(game.Workspace.CurrentCamera, TweenInfo.new(2, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), NumberTweenBack)

	local raycastResult = workspace:Raycast(cameraCF.Position, cameraCF.LookVector * length, params)

	if not raycastResult then return end

	if raycastResult.Instance then
		if raycastResult.Instance.Name == "TurnAroundPart" then
			if not deb then
				deb = true

				MainTweenBack:Cancel()
				MainTweenTo:Play()

				task.wait(1.5)

				Sound = true

				SoundTweenTo:Play()

				task.wait(0.2)

				TintBackTween:Cancel()

				TintToTween:Play()

				task.wait(0.2)

				game.Lighting.ColorCorrection.Enabled = false
				game.Lighting.ColorCorrection2.Enabled = true

				task.wait(0.2)

				game.Lighting.ColorCorrection.Enabled = true
				game.Lighting.ColorCorrection2.Enabled = false

				task.wait(0.2)

				game.Lighting.ColorCorrection.Enabled = false
				game.Lighting.ColorCorrection2.Enabled = true

				task.wait(0.2)

				game.Lighting.ColorCorrection.Enabled = true
				game.Lighting.ColorCorrection2.Enabled = false

				task.wait(0.2)

				game.TweenService:Create(game.Lighting.ColorCorrection, TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0), {TintColor = Color3.fromRGB(49, 0, 0)}):Play()
			else
				Sound = false
				deb = false

				MainTweenTo:Cancel()
				MainTweenBack:Play()
				TintToTween:Cancel()
				TintBackTween:Play()
			end
		else
			deb = false
			Sound = false

			MainTweenTo:Cancel()
			MainTweenBack:Play()
			TintToTween:Cancel()
			TintBackTween:Play()
		end
	else
		deb = false
		Sound = false

		MainTweenTo:Cancel()
		MainTweenBack:Play()
		TintToTween:Cancel()
		TintBackTween:Play()
	end
end

RunService.RenderStepped:Connect(function()
	if Sound then
		SoundTweenBack:Cancel()
		SoundTweenTo:Play()

		Raycast()
	else
		SoundTweenTo:Cancel()
		SoundTweenBack:Play()

		Raycast()
	end
end)

I organized it a bit.

I do not recommend to use ChatGPT for coding at all, given that it can screw up your script, or make code that doesn’t even work.

hey i hear people say this all the time, and whats really the difference? just wondering

ChatGPT is the worst programmer I’ve ever seen. I’d never rely on anything that thing has to say.

well chatgpt is very good for such task since all the correct data is given by the user

its just chatgpt fails at making scripts

-- Define constants and initial values
local WorkspaceService = game.Workspace
local Sound = false

local VolumeTo = { Volume = 1 }
local VolumeBack = { Volume = 0 }

-- Create tweens for sound volume
local SoundTweenTo = game.TweenService:Create(script.HB, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), VolumeTo)
local SoundTweenBack = game.TweenService:Create(script.HB, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), VolumeBack)

-- Function to perform raycasting
function Raycast()
    local deb = false
    local camera = workspace.CurrentCamera
    local cameraCF = camera.CFrame
    local length = 1000
    local params = RaycastParams.new()

    -- Define tweens for camera field of view and color correction
    local NumberTweenTo = { FieldOfView = 50 }
    local NumberTweenBack = { FieldOfView = 70 }
    local TintTo = { TintColor = Color3.fromRGB(255, 128, 128) }
    local TintBack = { TintColor = Color3.fromRGB(255, 255, 255) }
    local TintToTween = game.TweenService:Create(game.Lighting.ColorCorrection, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), TintTo)
    local TintBackTween = game.TweenService:Create(game.Lighting.ColorCorrection, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), TintBack)
    local MainTweenTo = game.TweenService:Create(game.Workspace.CurrentCamera, TweenInfo.new(4, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), NumberTweenTo)
    local MainTweenBack = game.TweenService:Create(game.Workspace.CurrentCamera, TweenInfo.new(2, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), NumberTweenBack)

    local raycastResult = workspace:Raycast(cameraCF.Position, cameraCF.LookVector * length, params)
    if raycastResult then
        if raycastResult.Instance and raycastResult.Instance.Name == "TurnAroundPart" then
            if not deb then
                deb = true
                MainTweenBack:Cancel()
                MainTweenTo:Play()
                wait(1.5)
                Sound = true
                SoundTweenTo:Play()
                wait(0.2)
                TintBackTween:Cancel()
                TintToTween:Play()
                wait(0.2)
                game.Lighting.ColorCorrection.Enabled = false
                game.Lighting.ColorCorrection2.Enabled = true
                for _ = 1, 2 do
                    wait(0.2)
                    game.Lighting.ColorCorrection.Enabled = not game.Lighting.ColorCorrection.Enabled
                    game.Lighting.ColorCorrection2.Enabled = not game.Lighting.ColorCorrection2.Enabled
                end
                game.TweenService:Create(game.Lighting.ColorCorrection, TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0), {TintColor = Color3.fromRGB(49, 0, 0)}):Play()
            else
                Sound = false
                deb = false
                MainTweenTo:Cancel()
                MainTweenBack:Play()
                TintToTween:Cancel()
                TintBackTween:Play()
            end
        else
            deb = false
            Sound = false
            MainTweenTo:Cancel()
            MainTweenBack:Play()
            TintToTween:Cancel()
            TintBackTween:Play()
        end
    else
        deb = false
        Sound = false
        MainTweenTo:Cancel()
        MainTweenBack:Play()
        TintToTween:Cancel()
        TintBackTween:Play()
    end
end

-- Connect to RenderStepped event to update sound and raycast
game["Run Service"].RenderStepped:Connect(function()
    if Sound then
        SoundTweenBack:Cancel()
        SoundTweenTo:Play()
        Raycast()
    else
        SoundTweenTo:Cancel()
        SoundTweenBack:Play()
        Raycast()
    end
end)

just to prove my point chatgpt managed to organize the script

FrostyTheDev This is not good formatting at all. Where did you ever pick this up. How can you possibly code like this. Notice every reply here is not so spaced out. Try to program more in blocks/chunks that can be summed up within a screen view. You can have a very long script but it’s made up of block/chunks like this. Look at GTX_3 script here… It’s made up of 5 chunks. Each one is easy to read and understand it’s role in the over all script.

Ok, I agree with that. As long as the prompt looks like this…

ChatGPT I want you to take away the spaces here and add some context to what it is doing. I do not want you to try to script anything. No guessing, no anything more than what I just told you. Just clean up this script without touching it with your logic in anyway other than what I have stated.

:joy::rofl: