I am currently working on a small project and am making an item which, after usage, increases the player’s FOV and plays a client sided sound. Each time I add or change code in the script however, it still doesn’t work. I have tried using a separate local script to convey the wanted actions, along with remote events, but each ends in either the tool breaking or the desired events not occurring. Can I get any help on this?
Current code of the tool (Doesn’t contain the sound, trying to get the FOV part down just to know that the code works)
local tool = script.Parent
local TweenService = game:GetService("TweenService")
local camera = workspace.CurrentCamera
local playeR = game.Players.LocalPlayer
local eventer = game:GetService("ReplicatedStorage").effects
tool.Activated:Connect(function()
tool:Deactivate() -- so people can't spam usage
wait(1) -- animation delay
local function effects(amount)
local tween = TweenService:Create(camera, TweenInfo.new(1, Enum.EasingStyle.Quint), {FieldOfView = camera.FieldOfView + 15})
tween:Play()
wait(5)
local tween2 = TweenService:Create(camera, TweenInfo.new(1, Enum.EasingStyle.Quint), {FieldOfView = camera.FieldOfView - 15})
tween2:Play()
end
eventer.OnServerEvent:Connect(function()
effects()
end)
local humanoid = tool.Parent:FindFirstChild("Humanoid")
humanoid.Health = humanoid.Health + 70
humanoid.WalkSpeed = 25
tool:Destroy()
wait(5)
humanoid.WalkSpeed = 16
end)
You need to declare the remote function outside of the activate and also the effects function activate is everytime the player clicks the button so it would make multi connections to these functions the way you had them try something like below also i setup a orig variable and debounce setup for activation
local tool = script.Parent
local TweenService = game:GetService("TweenService")
local camera = workspace.CurrentCamera
local playeR = game.Players.LocalPlayer
local eventer = game:GetService("ReplicatedStorage").effects
local debounce -- used as debounce so usage is not spammed
local OrigFieldOfView = camera.FieldOfView -- i would set an original and go off that incase it gets run 2x somehow
function effects(amount)
local tween = TweenService:Create(camera, TweenInfo.new(1, Enum.EasingStyle.Quint), {FieldOfView = OrigFieldOfView + 15})
tween:Play()
wait(5)
local tween2 = TweenService:Create(camera, TweenInfo.new(1, Enum.EasingStyle.Quint), {FieldOfView = OrigFieldOfView - 15})
tween2:Play()
end
eventer.OnServerEvent:Connect(function()
effects()
end)
tool.Activated:Connect(function()
if debounce then return end -- this could be used so ppl don't spam
debounce = true -- set true so only can run once until niled out after waits
--tool:Deactivate() -- so people can't spam usage
wait(1) -- animation delay
local humanoid = tool.Parent:FindFirstChild("Humanoid")
humanoid.Health = humanoid.Health + 70
humanoid.WalkSpeed = 25
tool:Destroy()
wait(5)
humanoid.WalkSpeed = 16
debounce = nil
end)