I’ve been trying to make a simple script using the knowledge I recently learned, but I keep failing, and I have no idea why the code won’t work, it’s slowly consuming my sanity… I want to make a simple dynamic: whenever you press a specific key, your field of view will increase, your camera will go greenish and a sound will play, all of that for a specified time; and after the time assigned has passed everything will return to normal (inspired by Halo 3).
The issue is semantic as long as I’m aware, there are no errors in the output. Something I think could be the problem is the UserInputState, I only want to listen for a key tap; not a press and release, so I only use the ‘Begin’ property and ignore the ‘End’ property, not sure if that’s what I should do.
I first solved the only output error I got, which was ‘Invalid arguments’ when trying to get a ModuleScript from ServerStorage, I just relocated the Module inside the LocalScript, and it stopped erroring. But after that, I’ve been trying to figure out why the rest of the code won’t work xc.
This is the LocalScript:
local ServerStorage = game:GetService("ServerStorage")
local ContextActionService = game:GetService("ContextActionService")
local FloodVoice = require(script.FloodVoice)
local COOLDOWN = 5
local function UserInput(actionName, inputState)
if actionName == Enum.UserInputState.Begin then
FloodVoice(true)
wait(COOLDOWN)
FloodVoice(false)
end
end
ContextActionService:BindAction("Flood", UserInput, false, Enum.KeyCode.M)
This is the ModuleScript:
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local StarterGui = game:GetService("StarterGui")
local FOV_FLOOD = 110
local FOV_STANDARD = 70
local SPEED_FLOOD = 2
local SPEED_STANDARD = 14
local SOUND = StarterGui.Sounds["Flood Sound"]
local SOUND_LENGHT = tonumber(SOUND.TimeLength)
local function FindHumanoid()
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character
if Character then
local Humanoid = Character:FindFirstChild("Humanoid")
return Humanoid
end
end
local function FindPlayer()
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character
if Character then
return LocalPlayer
end
end
local function CameraEffectsOn(player)
end
local function CameraEffectsOff(player)
end
local function FOV(pressedKey)
local Humanoid = FindHumanoid()
local Camera = Workspace.CurrentCamera
if Humanoid and Camera then
if pressedKey then
Camera.FieldOfView = FOV_FLOOD
Humanoid.WalkSpeed = SPEED_FLOOD
wait(15)
Camera.FieldOfView = FOV_STANDARD
Humanoid.WalkSpeed = SPEED_STANDARD
else
Camera.FieldOfView = FOV_STANDARD
end
end
end
return FOV
Also, the script’s location is inside the StarterPlayerScripts folder.