I was trying to edit SprintScript to make it enable effects for local player. It works in studio, but it doesnt work in game (Effects dont appear, it only changes WalkSpeed,FoV and JumpPower, puts sprint feature into infinite loop after i press shift while i am in game)

local mouse = game.Players.LocalPlayer:GetMouse()
local running = false

function getTool()	
	for _, kid in ipairs(script.Parent:GetChildren()) do
		if kid.className == "Tool" then return kid end
	end
	return nil
end


mouse.KeyDown:connect(function (key) -- Run function
	key = string.lower(key)
	if string.byte(key) == 48 then
		running = true
		local keyConnection = mouse.KeyUp:connect(function (key)
			if string.byte(key) == 48 then
				running = false
			end
		end)
		for i = 1,5 do
			game.Workspace.CurrentCamera.FieldOfView = (160)
			wait()
		end
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 248
		game.Players.LocalPlayer.Character.Humanoid.JumpPower = 250
		game.Workspace.CurrentCamera.CC.Enabled = true
		game.Workspace.CurrentCamera.Blur.Enabled = true
		game.Players.LocalPlayer.PlayerGui.Sound:Play()
		game.Players.LocalPlayer.PlayerGui.Peace:Stop()
		game.Players.LocalPlayer.PlayerGui.Run.Enabled = true
		repeat wait () until running == false
		keyConnection:disconnect()
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 12
		game.Players.LocalPlayer.Character.Humanoid.JumpPower = 50
		game.Workspace.CurrentCamera.CC.Enabled = false
		game.Workspace.CurrentCamera.Blur.Enabled = false
		game.Players.LocalPlayer.PlayerGui.Run.Enabled = false
		game.Players.LocalPlayer.PlayerGui.Sound:Stop()
		game.Players.LocalPlayer.PlayerGui.Peace:Play()
		for i = 1,5 do
			game.Workspace.CurrentCamera.FieldOfView = (70)
			wait()
		end
	end
end)

How can I fix it?

5 comments

2

First of all, mouse.KeyDown is deprecated. You should be using UserInputService. Second of all, is there any errors on the output?

0

There is no errors in output, Now i will try to convert it into the UserInputService

0

I have tried to do it, but with my knowing of my scripting i only broke it worse.

0

Wasted 2 hours on trying to make it work in game, nothing works.

0

Did you enable filtering, you'll need to turn it on for local effects to work.