Function stops working when character resets

So basically whenever my character resets the function below stops working, I’ve tried refreshing the character variable each time the character respawns however it still isn’t working.

CharacterAdded refresh:

LP.CharacterAdded:Connect(function(char2)
	character = char2
	humanoid = character:WaitForChild("Humanoid")
	print(character)
end)

Function:

character:WaitForChild("Values").KeyDown:GetPropertyChangedSignal("Value"):Connect(function()
	print("1")
	if character:WaitForChild("Values").KeyDown.Value == true then
		while character:WaitForChild("Values").KeyDown.Value == true do
			print("2")
			local mousepos = mouse.Hit.Position
			RS.va:FireServer("MouseUpdate", mousepos)
			wait(0.1)
		end
	end
end)

Any help is appreciated.

Where are those scripts located in?

I believe you could put them inside StarterCharacterScripts or StarterPlayerScripts, depending on your desires.

The script is located in StarterPlayerScripts so I don’t think that’s the problem.

Oops, my fault, I misread what you meant. I tried putting the script in StarterCharacterScripts and it ended up working. Thanks!

1 Like