Why my script isnt working

game.Workspace.Summonpart.ProximityPrompt.Triggered:Connect(function()
	wait(5)
	while true do wait(1.741)
		workspace.CurrentCamera.FieldOfView = 100
		local tweenservice = game:GetService("TweenService")
		local tweeninfo = TweenInfo.new(0.8)
		local thething = {}
		thething.FieldOfView = 70
		local tween = tweenservice:Create(workspace.CurrentCamera,tweeninfo,thething)
		tween:Play()
	end
end)

it doesnt give any errors in console
and it is local script

The probable main problem is that Summonpart and ProximityPrompt were accessed before they were initialized, WaitForChild() fixed that.

local summonPrompt = workspace:WaitForChild("Summonpart")
	:WaitForChild("ProximityPrompt")

summonPrompt.Triggered:Connect(function() --print("x")
	task.wait(5)
	while true do
		task.wait(1.741)
		local tween = game:GetService("TweenService"):Create(
			workspace.CurrentCamera,
			TweenInfo.new(0.8),
			{ FieldOfView = 70 }
		)
		workspace.CurrentCamera.FieldOfView = 100
		tween:Play()
	end
end)
variation
local summonPrompt = workspace:WaitForChild("Summonpart")
	:WaitForChild("ProximityPrompt")

local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(0.8)
local tweenProps = { FieldOfView = 70 }

summonPrompt.Triggered:Connect(function() task.wait(5)
	while task.wait(1.741) do workspace.CurrentCamera.FieldOfView = 100
		tweenService:Create(workspace.CurrentCamera, tweenInfo, tweenProps):Play()
	end
end)
variation

zoom in and out on repeat

local summonPrompt = workspace:WaitForChild("Summonpart")
	:WaitForChild("ProximityPrompt")

local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(1.741, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, true)
local tween = tweenService:Create(workspace.CurrentCamera, tweenInfo, { FieldOfView = 70 })

summonPrompt.Triggered:Connect(function()
	task.wait(5)
	workspace.CurrentCamera.FieldOfView = 100
	tween:Play()
end)

Not really handling a debounce here, not sure what this is for.

1 Like

Quick tip you should use task.wait() instead of wait() it is a deprecated function basically task.wait() is a better version of wait()

It doesnt work for some reason, i’ve tried doing the script and 2 variations inside 2 locations: inside the proximityprompt and ServerScriptService.
And the script is for changing player’s fov to 100 and tweening it back to 70 every 1.741 seconds when the proximityprompt is triggered

local part = workspace:WaitForChild("Summonpart")
local prompt = part.ProximityPrompt
local TWEEN_SERVICE = game:GetService("TweenService")
local CAMERA = workspace.CurrentCamera

local goal = {FieldOfView = 70}
local goal2 = {FieldOfView = 100}
local Fov70 = true

prompt.Triggered:Connect(function()
	task.wait(1)
	if Fov70 then
		TWEEN_SERVICE:Create(CAMERA,TweenInfo.new(2,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),goal2):Play()
		Fov70 = false
	else
		TWEEN_SERVICE:Create(CAMERA,TweenInfo.new(2,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),goal):Play()
		Fov70 = true
	end
end)

```I made a primitive switch
Can you explain what exactly you want?

I figured as much. Both locations are inappropriate for LocalScripts and thus render them naturally inoperable. As for Scripts, they’ll adjust the server’s Camera instance, not the client’s, so you’ll see no change. You need to move your LocalScript to StarterPlayerScripts. The following code is optimized:

--!strict
local TweenService = game:GetService("TweenService")


local Camera = workspace.CurrentCamera

local Part = workspace:WaitForChild("Part")
local ProximityPrompt = Part:WaitForChild("ProximityPrompt")


local TWEEN_INFO = TweenInfo.new(
	1.741,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.InOut
)

local TWEEN_IN = TweenService:Create(Camera, TWEEN_INFO, { FieldOfView = 70 })
local TWEEN_OUT = TweenService:Create(Camera, TWEEN_INFO, { FieldOfView = 100 })

	

local function onTriggered()
	while true do
		TWEEN_OUT:Play()
		TWEEN_OUT.Completed:Wait()
		
		TWEEN_IN:Play()
		TWEEN_IN.Completed:Wait()
	end
end



ProximityPrompt.Triggered:Connect(onTriggered)
1 Like

Did you notice I spell that differently .. ProximityPrompt. All of them work as they are, and were tested in the studio. I’m not used to setting up endless loops with no real viable exit and can overlap each other. So again, I’m not sure what you’re doing here. If two players use the same prompt it will most likely break. Not a fan of how any of them are set up.. as is.

thanks so much, now i can continute working on my game

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